在这里你去....
这是目录结构是什么,当我开始......
C:\Temp>tree /f
Folder PATH listing for volume OS
Volume serial number is XXXX-XXXX
C:.
│ file1.txt
│ run.bat
│
├───Source
│ 12abcd34.asc
│ 56efgh78.asc
│ testing.asc
│
└───Target
这是我将在以后运行的run.bat。 。包括bug修复...
C:\Temp>copy run.bat con
@Echo Off
title Test move files
set dir1=Source
dir %dir1%
Echo Directory Changed
FOR /f "eol=; delims=, " %%i in (file1.txt) do move /y "%dir1%\*%%i*.*" Target
1 file(s) copied.
现在我运行该批处理文件...
C:\Temp>run.bat
Volume in drive C is OS
Volume Serial Number is XXXX-XXXX
Directory of C:\Temp
19/07/2012 00:03 <DIR> .
19/07/2012 00:03 <DIR> ..
18/07/2012 23:59 0 12abcd34.asc
18/07/2012 23:59 0 56efgh78.asc
18/07/2012 23:59 0 testing.asc
3 File(s) 0 bytes
2 Dir(s) 41,653,194,752 bytes free
Directory Changed
C:\Temp\Source\12abcd34.asc
1 file(s) moved.
C:\Temp\Source\56efgh78.asc
1 file(s) moved.
现在,这是最终的目录结构...所以你可以看到,这是工作......
C:\Temp>tree /f
Folder PATH listing for volume OS
Volume serial number is XXXX-XXXX
C:.
│ file1.txt
│ run.bat
│
├───Source
│ testing.asc
│
└───Target
12abcd34.asc
56efgh78.asc
下面是for循环,你需要...
FOR /f "eol=; delims=, " %%i in (file1.txt) do move /y "%dir1%\*%%i*.*" Target
变化:
[1] within FOR you use %%i not %i.
[2] You need this format:
%dir1% <-- Where
\ <-- path delimiter
* <-- starts with anything
%%i <-- contains what you want to search
*.* <-- ends with anything
希望这会有所帮助。
在批处理文件中,'%i'必须有%加倍,如'%% i'。 – lavinio 2012-07-18 23:12:27