I have a text file containing a list of files and folders. What I want to do is use xcopy to replicate what is written in the text file. My text file looks like this:
Yes, you are close. Just need to use the existing path as the appended destination path.
@echo off
for /f "delims=" %%A in (textfile.txt) do if exist "%%~fA\*" (
md "C:\Output\%%~pA"
copy /y "%%~fA" "C:\Output\%%~pnxA"
)
If %%A
= "C:\Folder\Folder2\File3.txt", then %%~pA
= Folder\Folder2
@echo off
for /f "delims=" %%A in (textfile.txt) do (
md "C:\Output\%%~pA"
if not exist "%%~fA\*" echo f | xcopy "%%~fA" "C:\Output\%%~pnxA" /y
)
The if not exist "%%~fA\*"
makes sure to only copy the entry if it is not a directory. See Reference for more Techniques and Comments
Type in for /?
at the command line to view a list of the variable modifiers. %%~A
will remove the surrounding quotations (if any) from the variable.
Post about xcopy prompting issue. and fix #2.
Alternate Setup, since you most likely will not need the xcopy abilities.
@echo off
for /f "delims=" %%A in (textfile.txt) do (
md "C:\Output\%%~pA"
if not exist "%%~fA\*" copy /y "%%~fA" "C:\Output\%%~pnxA"
)