将具有文件夹结构的许多子文件夹中的文本文件中匹配字符串的文件复制到另一个目标文件夹

Copy files matching string(s) in a text file out of many subfolders with folder structure to another destination folder

我在文件夹结构中有很多 图像文件,如下所示:

/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
[...]

现在我有一个 filelist.txt,其中包含其中一些图像文件的列表,如下所示:

PictureRANDOMNAME1, PictureRANDOMNAME3, [...]

我想将与文本文件列表中的字符串匹配的所有图像从所有子文件夹复制到新目标(不移动它们),同时保持文件夹结构。

也许我需要一个批处理文件,我只是将它与所有子文件夹一起复制到主文件夹中,连同 filelist.txt,执行它并获得相同的文件夹结构,但只包含另一个目标上的所需文件.

特别之处在于路径和变音符号中的空格。

抱歉我的英语不好。老实说,我尽力了。也许一些母语人士可以帮助编辑更容易理解。

@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 从文件中获取行。由于每行以逗号分隔,%%b 将对行中的每个名称执行 xcopy

如果您愿意,可以在 xcopy 行的末尾添加 >nul 以禁止报告。

请注意 / 表示 winbatch 中的一个开关 - \ 是目录分隔符。

此程序未经测试。我建议你在依赖它作为你的实时数据之前,先用一个小的虚拟子目录树来验证它。