[英]Copy files matching string(s) in a text file out of many subfolders with folder structure to another destination folder
I have a lot of image files in a folder structure like this: 我在这样的文件夹结构中有很多图像文件 :
/Foldername1 (hohe Auflösung)/PictureRANDOMNAME1-FB.jpg
/Foldername1 (hohe Auflösung)/PictureRANDOMNAME2-FB.jpg
[...]
/Foldername2 (hohe Auflösung)/PictureRANDOMNAME1-SW.jpg
/Foldername2 (hohe Auflösung)/PictureRANDOMNAME2-SW.jpg
[...]
/Foldername3 (hohe Auflösung)/PictureRANDOMNAME1-SP.jpg
/Foldername3 (hohe Auflösung)/PictureRANDOMNAME2-SP.jpg
[...]
Now I have a filelist.txt with a list of some of these image files, like this: 现在,我有了一个filelist.txt ,其中包含其中一些图像文件的列表,如下所示:
PictureRANDOMNAME1, PictureRANDOMNAME3, [...]
I would like to copy all images matching the string(s) in the text file list out of all subfolders to a new destination (not moving them) while keeping the folder structure. 我想将与文本文件列表中的字符串匹配的所有图像从所有子文件夹中复制到新的目标位置(而不移动它们),同时保持文件夹结构。
Maybe I need a batch file that I just copy into the main folder with all the subfolders, together with a filelist.txt, execute it and get the same folder structure but only with the wanted files on another destination. 也许我需要一个批处理文件,然后将其与所有子文件夹一起复制到主文件夹中,并与filelist.txt一起执行,并获得相同的文件夹结构,但仅将所需文件放在另一个目标位置。
Special about this might be the spaces in the paths and the umlauts. 与此特别的可能是路径和变音符中的空格。
Sorry for my bad english. 对不起,我的英语不好。 I honestly tried my best.
老实说,我尽力了。 Maybe some native speaker could help editing to be more understandable.
也许一些母语人士可以帮助编辑变得更易懂。
@echo off
setlocal
:: This copies the tree structure from sourcedir to destdir
xcopy /t /e sourcedir destdir
:: This reads the filenames and copies the required files
for /f "delims=" %%a in (filelist.txt) do (
for %%b in (%%a) do xcopy /s /e sourcedir\%%b* destdir
)
%%a
acquires the lines from the file. %%a
从文件中获取行。 Since each line is comma-separated, %%b
will execute xcopy
on each name on the line. 由于每一行都用逗号分隔,
%%b
将对该行上的每个名称执行xcopy
。
You could add >nul
to the end of the xcopy
lines to suppress reporting if you like. 如果愿意,可以在
xcopy
行的末尾添加>nul
以禁止报告。
Please note that /
indicates a switch in winbatch - \\
is the directory-separator. 请注意,
/
表示winbatch中的一个开关- \\
是目录分隔符。
This procedure is untested. 此过程未经测试。 I suggest you try it against a small dummy subdirectory tree to verify it before relying on it for your live data.
我建议您在依赖于它的实时数据之前,对一个小的虚拟子目录树进行尝试,以对其进行验证。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.