2013-04-25 225 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