Computing.Net > Forums > Programming > Batch copy files on txt file incl. subdir.

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch copy files on txt file incl. subdir.

Reply to Message Icon

Name: nooorik
Date: September 29, 2009 at 20:28:14 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: September 30, 2009 at 02:11:36 Pacific
Reply:

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


0

Response Number 2
Name: nooorik
Date: September 30, 2009 at 19:08:30 Pacific
Reply:

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.


0

Response Number 3
Name: Mechanix2Go
Date: October 1, 2009 at 05:09:00 Pacific
Reply:

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


1

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Batch copy files on txt file incl. subdir.

Batch - Copy Files using .txt List www.computing.net/answers/programming/batch-copy-files-using-txt-list/18010.html

Batch deletion based on .txt file on ftp www.computing.net/answers/programming/batch-deletion-based-on-txt-file-on-ftp/20025.html

batch copy on file name string www.computing.net/answers/programming/batch-copy-on-file-name-string/19945.html