Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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.

That really doesn't work, I have files and folders mixed in the directory going about 6 directories deep
Thanks for your 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

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.txtfile.lst contains
d1\d11\f1.txt
d2\d22\f2.txt
f3.txtand 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 ignoredI am sorry about not providing enough
information. I hope, I made myself clear.
Thanks in advance

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]

![]() |
![]() |
![]() |

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