2016-11-15 22 views
0

我有一個簡單的命令,它拷貝一個文件夾中的所有PDF文件的子文件夾到另一條路徑:從CMD轉換一個簡單的命令,一個批處理文件

for /r "c:\users\user\documents" %i in (*.pdf) do copy "%~fi" "d:\alla\%~nxi" 

如何轉換該命令到批處理文件?當我將它從Notepad保存爲script.bat並運行時,沒有任何事情發生。

+0

這是RTM時刻之一。 – Squashman

回答

1

的文件(可通過在命令提示符下鍵入for /?help for解釋這個問題,我強調以下部分引用的相關部分

對一組文件中的每個文件運行指定的命令

FOR%變量IN(設置)DO命令[c ommand參數]

%variable   Specifies a single letter replaceable parameter. 
    (set)    Specifies a set of one or more files. Wildcards may be used. 
    command    Specifies the command to carry out for each file. 
    command-parameters Specifies parameters or switches for the specified command. 

在批處理程序使用FOR命令,指定%%變量而不是%變量的 。變量名稱區分大小寫,因此%i與%I的 不同。

因此,儘管在命令行中您的命令工作,爲了從一個批處理文件中使用它,你需要的%跡象變量前增加一倍。

for /r "c:\users\user\documents" %%i in (*.pdf) do copy "%%~fi" "d:\alla\%%~nxi" 
1

試試這個:

@for /r "c:\users\user\documents" %%i in (*.pdf) do @copy "%%~fi" "d:\alla\%%~nxi" 
相關問題