Batch copy files on txt file incl. subdir.

September 29, 2009 at 20:28:14
Specs: Windows XP
Hi.
I'd like to batch copy only files, including files in subdirectories, listed in other txt. file.

For example, if I want to copy a whole directory with subdirectories, I do something like this:
--
@echo off
for /f %%a ('dir /b/s c:\data') do (
copy %%a c:\bkup
)
--

How can I copy only files listed in a txt file?

txt file I mentioned looks like this:
--
some.pdf
some.xls
brahbrah.doc
aaaaaa.txt
adfafd.xls
:
:
--
(yeah, only file names, no directory paths.)

Any help will be appreciated.

Thanks


See More: Batch copy files on txt file incl. subdir.

Report •


#1
September 30, 2009 at 02:11:36
Use a second, nested for loop (the first does the dir) which checks to see if the filename is in your list.


=====================================
Helping others achieve escape felicity

M2


Report •

#2
September 30, 2009 at 19:08:30
Thanks Mechanix2Go

OK, I followed your instruction and wrote something like this:
--
@echo off
for /f "delims=" %%A in (sample.txt) do (
for /f "delims=" %%B in ('dir /s /b C:\document\') do copy %%B D:\bkup\
)
--

However, when I run this batch, it seems the batch ignores sample.txt and copies all files (incl. files in subdir) into D:\bkup\ instead.

Then I am stuck again.


Report •

#3
October 1, 2009 at 05:09:00
not tested

=========================
@echo off & setLocal EnableDELAYedExpansion

for /f "tokens=* delims= " %%a in ('dir/s/b/a-d C:\document') do (
find /i "%%~NXa" < sample.txt > nul
if not errorlevel 1 (
copy "%%a" D:\bkup
)
)


=====================================
Helping others achieve escape felicity

M2


Report •

Related Solutions


Ask Question