批处理文件从一个文件的内容复制文件 [英] Batch file to copy files from a file contents
问题描述
我有哪里一些名字都保存在内容的主文件( FILE1.TXT
)。我必须找到所有有一个文件夹中的一种名称(外卡)的文件,并使用批处理文件的程序将其移动到不同的文件夹。
例如: FILE1.TXT
的内容
ABCD
EFGH
现在该文件夹中讲 C:\\ TEMP \\源
我有这样
12abcd34.asc
56efgh78.asc
testing.asc
我,只有那些2文件到一个文件夹移动说C:\\ TEMP \\目标
下面是我的code,但它给错误说我是*。*意外在这个时候。你能帮帮。
@回响
标题测试移动文件
集方向1 = C:\\ TEMP \\来源
DIR%DIR1%
回声目录已更改
FOR / FEOL =; delims =%i的(FILE1.TXT)不要移动/ Y*%我*。*目标
在这里,你去....
这是目录结构是什么,当我开始...
C:\\ TEMP>树/˚F
文件夹路径音量OS上市
卷序列号为XXXX-XXXX
C:。
│FILE1.TXT
│的run.bat
│
├───Source
│12abcd34.asc
│56efgh78.asc
│testing.asc
│
└───Target
这是我将在后面跑..包括bug修复的run.bat ...
C:\\ TEMP>复制的run.bat CON
@回响标题测试移动文件设置DIR1 =源DIR%DIR1%回声目录已更改FOR / FEOL =; delims =%%我(FILE1.TXT)不要移动/ Y%DIR1%\\ * %%我*。*目标
1文件(S)复制。
现在我运行该批处理文件...
C:\\ TEMP>的run.bat
在驱动器C卷是OS
卷序列号是XXXX-XXXX 的C目录:\\ TEMP19/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文件(S)0字节
2目录(S)41653194752字节免费
目录已更改
C:\\ TEMP \\来源\\ 12abcd34.asc
1文件(S)移动。
C:\\ TEMP \\来源\\ 56efgh78.asc
1文件(S)移动。
现在这是最后的目录结构...所以你可以看到,这是工作......
C:\\ TEMP>树/˚F
文件夹路径音量OS上市
卷序列号为XXXX-XXXX
C:。
│FILE1.TXT
│的run.bat
│
├───Source
│testing.asc
│
└───Target
12abcd34.asc
56efgh78.asc
下面是for循环需要...
FOR / FEOL =; delims =%%我(FILE1.TXT)不要移动/ Y%DIR1%\\ * %%我*。*目标
的变化:
[1]内为你使用%%我不是%I。
[2]你需要这个格式:%DIR1%LT; - 在哪里
\\< - 路径分隔符
*< - 启动与任何
%% I< - 包含要搜索的内容
*。*< - 与任何结束
希望这有助于。
I have a master file (File1.txt
) where some names are maintained in the contents. I have to find all the files which has those kind of names (wild cards) in a folder and move them to a different folder using batch file program.
Eg : File1.txt
has contents
abcd
efgh
now in the folder say c:\temp\Source
i have files like
12abcd34.asc
56efgh78.asc
testing.asc
I have to move only those 2 files to a folder say c:\temp\Target.
Here's my code, but it gives error saying i*.* is unexpected at this time. Can you please help .
@Echo Off
title Test move files
set dir1=C:\temp\Source
dir %dir1%
Echo Directory Changed
FOR /f "eol=; delims=, " %i in (file1.txt) do move /y "*%i*.*" Target
Here you go....
This is what the directory structure is when I start...
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
This is the run.bat that I will run later .. includes the bug fixes...
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.
Now I run the batch file ...
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.
Now this is the final directory structure ... so you can see that it is working ...
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
Here is the for loop you need...
FOR /f "eol=; delims=, " %%i in (file1.txt) do move /y "%dir1%\*%%i*.*" Target
Changes:
[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
Hope this helps.
这篇关于批处理文件从一个文件的内容复制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!