2016-07-15 106 views
1

目錄我有一個bat文件看起來像的哪個部分:循環通過目錄中的蝙蝠,往上用bat文件

set test=test 
for /d %%x in (..\*.%test%) do xcopy "%%x" c:\path\%test%\%%x\ /S /E /F 
xcopy ..\dir c:\path\%test%\dir\ /S /E /F 

for循環不工作,而是XCOPY一樣。如果我將上面的目錄的內容移動到當前目錄並更改代碼以刪除「.. \」:

for /d %%x in (*.%test%) do xcopy "%%x" c:\path\%test%\%%x\ /S /E /F 

它的工作原理。有人可以告訴我爲什麼for循環中的bat腳本無法查找目錄嗎?我接近這個錯誤嗎?

編輯:我現在已經改變了命令看到的部份答案後,但它仍然不能正常工作:

for /d %%~nxx in (..\*.%MUI%) do xcopy "%%~nxx" c:\temp\%test%\%%~nxx\ /S /E /F 

我收到的錯誤:

%~nxx was unexpected at this time 

編輯#2: 我仍然無法工作,我的命令看起來像

for /d %%x in (..\*.%test%) do xcopy "%%~nxx" c:\temp\%test%\%%~nxx\ /S /E /F 

for /d %%x in (..\*.%test%) do xcopy "%%x" c:\temp\%test%\%%~nxx\ /S /E /F 

回答

0

它可以。但%%x將包含..\xyz.test,而不是xyz.test,這可能不是您想要在您的xcopy目標中。

將其替換爲%%~nxx(用於「名稱和x的擴展」)以切斷路徑。

for /d %%x in (..\*.%test%) do xcopy "%%x" c:\path\%test%\%%~nxx\ /S /E /F

+0

你可以輸入行嗎?我很困惑,在哪裏改變%%〜nxx – user2455869

+0

你使用雙重百分號嗎?你把它放在xcopy目標部分嗎?也許使用大寫變量,因爲小寫字母x可能與〜x標識符衝突。 – ths

+0

我收錄了一個顯示我已經完成的編輯 – user2455869