问题
So when I copy using the dirs %userprofile%\Desktop\Out and %userprofile%\Desktop\Out\test The .txt are copied over however I get the error The file cannot be copied onto itself.
When I run the script with %userprofile%\Desktop\Out and %userprofile%\Desktop\New Folder It runs smoothly.
So my question is why does the script get confused when you copy from a common root folder to a different sub folder?
@ECHO ON
FOR /r "%userprofile%\Desktop\Out" %%a IN (*.txt) DO copy "%%a" "%userprofile%\Desktop\New Folder"
pause
回答1:
The destination directory %userprofile%\Desktop\Out\test is a subdirectory of the source, whereas %userprofile%\Desktop\New Folder is not.
Since you are using for /r, the copied files would be copied from the lower directory as the recursion takes place - FROM the destination directory INTO the destination directory. Hence, a file would be copied over itself.
来源:https://stackoverflow.com/questions/39571781/copy-in-for-loop-works-but-keeps-giving-the-error-the-file-cannot-be-copied-ont