简体   繁体   English

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

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

相关问题 查找所有文件并复制到另一个保留文件夹结构的目标位置 - Find all files and copy to another destination keeping the folder structure 如何将几个指定的文件从源文件夹及其子文件夹复制到目标文件夹? - How to copy several specified files from a source folder and its subfolders to a destination folder? 如何使用Windows命令将文件夹结构和文件复制到目标位置? - How to copy the folder structure and files into the destination using a Windows command? 将文件复制到文件夹的所有子文件夹 - Copy a file to all subfolders of a folder 将通配符文件夹结构文件移动到目标文件夹 - Move Wildcard Folder structure files to a destination folder 使用 dir 批量获取文件夹目标(cmd)并在找到的名称文件夹中复制+粘贴文件 - Batch using dir to get folder destination (cmd) and copy+paste files in name's folder found 使用Windows cmd读取文件夹的子文件夹和这些子文件夹中的文件 - Read a Folder's subfolders and files in these subfolders using Windows cmd 如何将x天的旧文件从文件夹和子文件夹复制到新位置,同时保持Windows中当前的文件夹结构? - how to copy x days old files from folders and subfolders to new location while maintaining current folder structure in windows? Windows批处理将文件从子文件夹复制到一个文件夹 - Windows batch copy files from subfolders to one folder DropIt如何从文件夹和子文件夹复制pdf文件 - DropIt how to copy pdf files from folder and subfolders
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM