Recursive copy from text list

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
carnagel
Posts: 3
Joined: 27 Nov 2014 09:41

Recursive copy from text list

#1 Post by carnagel » 27 Nov 2014 09:48

Hi,

Looking to batch copy a list of files from a text list, recursively through all sub-directories please.

I have a working batch for a single directory - just need the recursive added, if possible.

Code: Select all

@echo off
set Source=D:\mydirectory\myfiles
set Target=D:\tmp
set FileList=C:\Users\Administrator\Desktop\move.txt
echo.

if not exist "%Source%" echo Source folder "%Source%" not found & goto Exit
if not exist "%FileList%" echo File list "%FileList%" not found & goto Exit
if not exist "%Target%" md "%Target%"

for /F "delims=" %%a in ('type "%FileList%"') do copy "%Source%\%%a" "%Target%"

:Exit
echo.
echo press the Space Bar to close this window.
pause > nul


Thanks.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Recursive copy from text list

#2 Post by foxidrive » 27 Nov 2014 13:07

You want to copy files that are in a text file?

What does your text file look like?

carnagel
Posts: 3
Joined: 27 Nov 2014 09:41

Re: Recursive copy from text list

#3 Post by carnagel » 27 Nov 2014 15:00

foxidrive wrote:You want to copy files that are in a text file?

What does your text file look like?


it just contains file names, not paths

filename.mp4
filename2.mp4

etc

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Recursive copy from text list

#4 Post by foxidrive » 27 Nov 2014 16:23

Test this:

edited

Code: Select all

@echo off
set "Source=D:\mydirectory\myfiles"
set "Target=D:\tmp"
set "FileList=C:\Users\Administrator\Desktop\move.txt"
echo.

if not exist "%Source%" echo Source folder "%Source%" not found & goto Exit
if not exist "%FileList%" echo File list "%FileList%" not found & goto Exit
if not exist "%Target%" md "%Target%"

for /F "delims=" %%a in ('type "%FileList%"') do (
   for /f "delims=" %%b in ('dir "%Source%\%%a" /b /s /a-d ') do echo copying "%%b"&xcopy /b "%%b" "%Target%%%~pb" >nul
)
:Exit
echo.
echo press the Space Bar to close this window.
pause > nul

carnagel
Posts: 3
Joined: 27 Nov 2014 09:41

Re: Recursive copy from text list

#5 Post by carnagel » 28 Nov 2014 00:53

Worked perfectly

Thanks very much for your help.

Post Reply