[英]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 .我想在rimraf package 的帮助下使用globs删除
dist/a
文件夹和dist/b
文件夹(基本上是所有子文件夹)。
I have installed rimraf
globally as so npm i -g rimraf
.我已经在全球范围内安装了
rimraf
,所以npm i -g rimraf
。
I tried doing rimraf dist/**
, rimraf dist/*
, rimraf dist/**/
, rimraf dist/**/*
but it complete wipes out everything inside dist/
directory.我尝试做
rimraf dist/**
, rimraf dist/*
, rimraf dist/**/
, rimraf dist/**/*
但它完全清除了dist/
目录中的所有内容。
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.我知道我可以像
rimraf dist/a && rimraf dist/b
那样单独做,但我想使用globs
,因为我的 Node 项目中有很多目录。 Also, this is a part of an npm script but just to give an example I made a short usecase:)此外,这是 npm 脚本的一部分,但只是举个例子,我做了一个简短的用例:)
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:(我还发现del package 与
rimraf
非常相似,但也无法使其工作:(
You can simply use rimraf dist/*/
to remove all the subfolders within a particular folder.您可以简单地使用
rimraf dist/*/
删除特定文件夹中的所有子文件夹。
This will remove subfolders and will preserve all the other extensions file.这将删除子文件夹并保留所有其他扩展文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.