复制文件列表(txt) [英] Copy a list (txt) of files

查看:79
本文介绍了复制文件列表(txt)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看过SO上的一些脚本示例,但是似乎都没有提供如何从.txt列表中读取文件名的示例.

I've seen some scripts examples over SO, but none of them seems to provide examples of how to read filenames from a .txt list.

这个例子很好,可以将所有文件从A复制到B文件夹

This example is good, so as to copy all files from A to B folder

xcopy c:\olddir\*.java c:\newdir /D /E /Q /Y

但是我需要类似下一个的东西,在这里我可以实际填充源文件夹和目标文件夹:

But I need something like the next, where I can fill actually the source and destination folder:

 @echo off
 set src_folder = c:\whatever\*.*
 set dst_folder = c:\foo
 xcopy /S/E/U %src_folder% %dst_folder%

这些*.*而不是src_folder = c:\whatever\*.*,需要是从txt文件读取的文件列表.

And instead of src_folder = c:\whatever\*.*, those *.* need to be list of files read from a txt file.

File-list.txt(示例)

File-list.txt (example)

file1.pds
filex.pbd
blah1.xls

有人可以建议我怎么做吗?

Could someone suggest me how to do it?

推荐答案

给出名为File-list.txt的文件中的文件名列表,以下几行应该可以满足您的要求:

Given your list of file names in a file called File-list.txt, the following lines should do what you want:

@echo off
set src_folder=c:\whatever
set dst_folder=c:\target
for /f "tokens=*" %%i in (File-list.txt) DO (
    xcopy /S/E "%src_folder%\%%i" "%dst_folder%"
)

这篇关于复制文件列表(txt)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆