Find and copy files from .txt list

March 9, 2010 at 14:17:25
Specs: Windows XP
Hoping someone can help me with a batch file. I have found similar questions answered, but not knowing anything about .bat programming I don't understand them enough to make the edits I would need for it to work.

I need it to search for all the files contained in a list saved as a text file "F:\Reports\FileList.txt"

It needs to search in F:\Reports and all of the subfolders in F:\Reports

Then copy those files to another folder F:\Reports\CopiedFiles


Thanks,
Ronnie


See More: Find and copy files from .txt list

Report •


#1
March 9, 2010 at 21:52:17
here's my probably defective attempt, but maybe you can make it work:
@echo & setlocal
pushd f:\reports
md copdfiles 2>nul
for /f "tokens=*" %%a in (filelist.txt) do (
for /f "tokens=* %%b in ('dir /s /a-d /b %%a') do copy %%b copdfiles
)
::----- end -------
not tested!

Report •

#2
March 10, 2010 at 05:41:04
Thanks for the response nbrane.

I wish I knew more about batch code. I will have to spend some time in the future learning more about the code.

The code you suggested creates a folder "copdfiles" in the directory that the batch file is located but does nothing else.

I did some searching and tried to edit other's suggested code and came up with the code below, but it shows that the files are not found if they are in a subdirectory.

Anyway thanks again for your response.

[code]
@echo off
pause
for /f %%a in (F:\Reports\FileList.txt) do (
xcopy %%a F:\Reports\CopiedFiles
)
pause
[/code]


Report •

#3
March 10, 2010 at 15:28:20
i forgot a parenth (imagine that!). If you want to give it another shot, try this revised version:

@echo & setlocal
pushd f:\reports
md copdfiles 2>nul
for /f "tokens=*" %%a in (filelist.txt) do (
for /f "tokens=* %%b in ('dir /s /a-d /b %%a') do copy %%b copdfiles
)
)

:: ----- end ------
it is designed to pull files from all subdirectories ("dir /s")
no testing is done for identical filenames in diff. direcories.


Report •
Related Solutions


Ask Question