Computing.Net > Forums > Programming > Batch to copy files in a list

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 to copy files in a list

Reply to Message Icon

Name: rojanu
Date: July 17, 2008 at 07:26:52 Pacific
OS: Windows XP SP2
CPU/Ram: intel p4 1024 Mb ram
Comment:

I have a list of file paths in a txt. I want to copy the files to another directory keeping the directory structure which they are in



Sponsored Link
Ads by Google

Response Number 1
Name: Balkrah (by Vaughan Newton)
Date: July 17, 2008 at 08:55:05 Pacific
Reply:

Assuming that the listed paths are directories:


for /f "tokens=*" %%a in (list.txt) do (
mkdir "dst\%%~na"
xcopy "%%a" "dst\%%~na" /E /I
)

Just replace myfile.txt and dst with the appropriate names.


0

Response Number 2
Name: rojanu
Date: July 17, 2008 at 13:35:37 Pacific
Reply:

That really doesn't work, I have files and folders mixed in the directory going about 6 directories deep

Thanks for your reply


0

Response Number 3
Name: rprgrmr
Date: July 17, 2008 at 18:04:39 Pacific
Reply:

How, exactly doesn't it work? Saying flatly that it doesn't work doesn't help anyone help you. Certainly it helps some. Do you understand what is being done in the example given? If you can figure it out, perhaps you can modify it to do what you need. I don't know if does what you want or not, but I can tell it certainly contains the clues you need to do what you want.

rprgrmr


0

Response Number 4
Name: rojanu
Date: July 18, 2008 at 00:53:21 Pacific
Reply:


OK, First of all
[Quote from Balkrah]
Assuming that the listed paths are directories:
[/Quote]
[Quote from my post]
I have files and folders mixed in the directory
going about 6 directories deep
[/Quote]
And top of that the file list I have is only a
list of files it hasn't got any entries for
directories only.

When I use that code each entry is treated as a
directory and therefore a directory is
created but not even in the correct tree
structure.

Created test structure
d1
|--d11
| |--f1.txt
d2
|--d22
| |--f2.txt
f3.txt

file.lst contains
d1\d11\f1.txt
d2\d22\f2.txt
f3.txt

and output is
dst
|--f1
|--f1.txt
|
f2
|--f2.txt
|
f3
it can be seen in the result code only
created a folder with the file name, no matter
where in the tree it was and if the
file wasn't in a sub directory a folder is only
created and file is ignored

I am sorry about not providing enough
information. I hope, I made myself clear.


Thanks in advance



0

Response Number 5
Name: rojanu
Date: July 21, 2008 at 08:18:19 Pacific
Reply:


Here is the workaround I did to get what I wan't,

First I included all of the folder names as well as file names
and then

[CODE]
FOR /f "tokens=*" %%X IN (list.txt) DO (
:: Check if entry is a directory in the source
IF EXIST %%X\nul (
:: Create if destination directory does not exist
IF NOT EXIST dst\%%X\nul (
MKDIR dst\%%X
)
)
IF NOT EXIST %%X\nul (
COPY %%X dst\%%X /y
)
)
[/CODE]



0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch to copy files in a list

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

batch to count files in DIR then send email www.computing.net/answers/programming/batch-to-count-files-in-dir-then-send-email/19628.html

Batch to move all files in a list. www.computing.net/answers/programming/batch-to-move-all-files-in-a-list/16817.html