Search code examples
windowsbatch-filecmddos

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.jpg , theImage.jpg, parisImage.jpg (This is a flie that I will format it does not matter filee names are seperated with comma, or line break)

And there is a folder named /MyImageFolder, which contains lets say 1000 images, and also contains myImage1.jpg , theImage.jpg, parisImage.jpg

I want to find those given images and copy them to another directory.


I want to search given file names in needToFind.txt, in a directory/folder MyImages, which contains many images. And copy founded images to another directory/folder, such as MyGivenSetOfImages.

Please help, this will save my life.

Thanks


Solution

  • Format needToFind.txt to have one file name per line. The following simple batch script should work.

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

    It can be done on the command line without a batch file: just change each %% to %.