2011-10-31 98 views
2

我有迷你遞歸功能,它可以查找和隱藏所有.mta文件。它看起來像遇到問題.bat文件

For /r %1 in (*.mta) do attrib +h "%1" 

當我試圖從命令提示符下執行它手動,它工作正常

enter image description here

我.bat文件創建。代碼看起來像

D: 
For /r %1 in (*.mta) do attrib +h "%1" 
pause 

試圖執行此文件。剛開了這個畫面

enter image description here

有什麼不好的代碼?

+0

一般來說,這個鏈接對於這些問題非常有用:http://ss64.com/nt/syntax-args.html – morechilli

回答

4

與嘗試:

For /r %%i in (*.mta) do attrib +h "%%i" 

(名稱爲您的文件.cmd,它看起來更加現代。)

不要使用%1,這是指你的腳本的參數,所以它will not work。在命令行中使用%,在批處理腳本中使用%%

0

%1是傳遞給批處理文件的命令行參數,在這種情況下恰好爲空。這意味着您的for循環語法不正確。使用一些其他的變量名稱,而不是像%F:

for /r %f in (*.mta) do attrib +h "%f" 

如果你想用你的版本,不要這樣:

c:\> yourbatch.bat f 

然後%F就已經擴大到只是「f」和你'd得到:

for /r f in (*.mta) do attrib +h "f" 

這也是不正確的。

+0

使用f,它給出的命令的消息sytax是不正確的http:// prntscr。 com/3s0t3 –

+0

正如Mat提到的,%1可能會混淆,但它也是合法的循環變量,唯一的問題是缺少第二個百分比 – jeb