创建一个批处理文件删除多个,分离子目录 [英] Creating a batch file to delete multiple, separated subdirectories

查看:158
本文介绍了创建一个批处理文件删除多个,分离子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试下面的目录结构下删除文件夹(及其内容): C:\\ ROOT \\ * \\文件夹,其中*是一个变量,单亲目录。我试着使用:

I am attempting to delete folders (and their contents) under the following directory structure: C:\Root\*\Folder, where * is a variable, single parent directory. I tried using:

rmdir /s /q "C:\Root\*\Folder"

不过,我学到了通配符只能出现在最后一个目录。我发现涉及将文件复制到一个共同的目的地有类似的问题。解决的办法是:

However, I learned wildcards may only appear in the last directory. I found a similar problem involving copying files to a common destination. The solution was:

for /f "usebackq delims=" %m in (`dir /b c:\users`) do copy "C:\Users\%m\AppData\Roaming\LordEpicalsFiles\Info.txt" "C:\My_Files\%m_Info.txt"

(原贴)

不过,我试图分析,然后应用code失败。这里是我的尝试:

However, my attempt to parse and then apply the code failed. Here is my attempt:

for /f "usebackq delims=" %m in (`dir /b C:\Root:`) do rmdir /s /q "C:\Root\%m\Folder"

任何意见和想法是极大的AP preciated。谢谢你在前进!

Any comments and thoughts are greatly appreciated. Thank you in advance!

推荐答案

这在这里会给你用C目录的列表:\\用户:

This here will give you a list of directories in C:\users:

for /d %d in ("C:\Root\*") do echo %~nd

根据,如果你需要的完整路径(这意味着 C:\\ ROOT \\ 在内),你可以离开〜N 退出

Depending if you need the full path (that means C:\Root\ included) you can leave the ~n out

所以这(谨慎使用)会删除你想要什么:

So this (use with care) will delete what you want:

for /d %d in ("C:\Root\*") do echo rd "%d\Folder" /S /Q 

(删除回声当你确定这是你想要什么)

(Remove the echo when you are sure this does what you want)

请注意,我包装在引号的路径,这是必要的,当您的路径(不同于示例)包含空格。

Please note that I wrapped the path in quotation marks, this is necessary when your path (unlike the example) contains spaces.

这篇关于创建一个批处理文件删除多个,分离子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆