search given set of file names.* in all sub direct

2019-03-03 09:20发布

问题:

I need extension to this question: search given set of files and copy to another directory

There is a given set of file names in a needToFind.txt file such as:

myImage1 , theImage, parisImage (one file name per line)

And there is a folder named /MyImageFolder, which contains lets say 1000 images in its subfolders and itself, and also contains myImage1.jpg ,myImage1.png, theImage.jpg, parisImage.jpg, parisImage.png,parisImage.tiff

I want to find those given image names without looking file extension and copy them to another directory.

Thanks a lot

回答1:

@echo off
cd "\MyImageFolder"
for /f "usebackq eol=: delims=" %%F in ("needToFind.txt") do copy "%%~F.*" "\anotherFolder"

If the provided file names already have extensions, and you want to ignore the extensions, you can use

@echo off
cd "\MyImageFolder"
for /f "usebackq eol=: delims=" %%F in ("needToFind.txt") do copy "%%~nF.*" "\anotherFolder"


回答2:

@echo off
cd "\MyImageFolder"
for /F "usebackq delims=" %%a in ("needToFind.txt") do (
   for /R %%b in ("%%~Na.*") do copy "%%b" "\anotherFolder"
)