How do I copy file and folder structure using xcopy from a text file?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 22:13:53
David Ruhmann

Yes, you are close. Just need to use the existing path as the appended destination path.

Update

@echo off
for /f "delims=" %%A in (textfile.txt) do if exist "%%~fA\*" (
    md "C:\Output\%%~pA"
    copy /y "%%~fA" "C:\Output\%%~pnxA"
)

Original

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"
)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!