简体   繁体   中英

Remove all subfolders in Node using globs with the help of rimraf package?

I have the following directory structure:

dist
├── a/
├── b/
├── a.md
└── b.md

I want to remove the dist/a folder & dist/b folder (basically all subfolders) with the help of rimraf package using globs .

I have installed rimraf globally as so npm i -g rimraf .

I tried doing rimraf dist/** , rimraf dist/* , rimraf dist/**/ , rimraf dist/**/* but it complete wipes out everything inside dist/ directory.

I know I can do individually like rimraf dist/a && rimraf dist/b but I want to use globs since there are many directories in my Node project. Also, this is a part of an npm script but just to give an example I made a short usecase:)

Anyway to do it cross-platform? I also found del package which is quite similar to rimraf but can't get it to work either:(

You can simply use rimraf dist/*/ to remove all the subfolders within a particular folder.

This will remove subfolders and will preserve all the other extensions file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM