2013-04-25 52 views
2

我正在研究需要从文件夹中删除文件夹的应用程序。但文件夹名称将具有相同的通用名称减去其结尾。 NA_monthlyGP_20130131,数字会改变。它位于以下路径C:\Inbound\Extract我想删除它但保留父目录Extract使用通配符删除DOS目录

+0

为什么这个标记为ms-dos?这实际上是否适用于DOS或Windows版本? – JJS 2015-11-09 16:57:16

回答

4

双%迹象在批处理文件中使用它。

@echo off 
for /d %%a in ("C:\Inbound\Extract\NA_monthlyGP_*") do rd /s /q "%%~a" 
+0

谢谢!工作很棒! – user2133071 2013-04-29 15:43:48

0

试试这个命令行:

for /d %i in (NA_monthlyGP_*) do rd "%~i" 
+0

这没有做任何事情。没有错误信息或任何东西。 – user2133071 2013-04-25 21:10:24

+0

从您的'Extract'文件夹中启动它。 – Endoro 2013-04-25 21:19:38

0

forfiles /P C:\Inbound\Extract /M NA_monthlyGP_* /C "cmd /c if @isdir==TRUE rmdir /s /q @file"

forfiles允许命令行用户用于在位置上的每个文件运行命令。在Windows Vista/Server 2003及更高版本中可用。

 
/p pathname Indicates the path to start searching. 
       The default folder is the current working directory (.). 
/M searchmask Searches files according to a searchmask. 
       The default searchmask is '*' . 
/C command  Indicates the command to execute for each file. 
       Command strings should be wrapped in double quotes. 
       The default command is "cmd /c echo @file". 
+0

你能否在[编辑]中解释为什么这个命令回答这个问题?仅限代码答案[阻止](http://meta.stackexchange.com/q/148272/274165),因为他们没有教导解决方案。 (提到'forfiles'的版本将起作用。) – 2015-11-07 03:00:23

+0

@NathanTuggy更新了描述。如果您希望看到其他评论,请告诉我。你使用这个解决方案吗?你为什么评论? – JJS 2015-11-09 16:57:56

+0

它出现在LQP队列中,我并不特别希望别人有一个不好的借口来删除它。 – 2015-11-09 17:56:14