FOR / R %%我会回复一些奇怪的事情

时间:2015-04-19 12:08:32

标签: batch-file for-loop cmd

pushd %~dp0
set actdir=%cd%
mkdir "%cd%\numbers"
SET count=1
for /R %%i in ("C:\Users\me\Desktop\bt") do (call :subroutine %%i %~xi)
GOTO :eof

尝试以递归方式从文件夹(以及子文件夹)获取所有文件,以将它们复制/重命名为其他路径。

%%我正在回归一些非常奇怪的事情。确切地说,这个:

C:\Users\me\Documents\RunningBatchFolder\"C:\Users\me\Desktop\bt"

所以就像两个组合路径。 怎么会?如何解决这个问题?

另外一个问题,%~xi给出错误:The following usage of the path operator in batch-parameter substitution is invalid: %~xi

1 个答案:

答案 0 :(得分:3)

尝试这样:

for /R "C:\Users\me\Desktop\bt" %%i in (*) do (call :subroutine %%i %~xi)

这里有更多info

    Unlike some other variants of the FOR command you must include a wildcard 
   (either * or ?) in the 'set' to get consistent results returned. In many    cases
    you can work around this by adding a single character wildcard e.g. if you 
    are looping through multiple folders to find the exact filename myfile.txt 
    you could instead specify myfile.t?t