在FOR循环中复制可正常工作,但始终显示错误“无法将文件复制到自身上". [英] Copy in FOR loop works but keeps giving the error "The file cannot be copied onto itself"
问题描述
因此,当我使用目录%userprofile%\Desktop\Out
和%userprofile%\Desktop\Out\test
复制时,.txt
被复制了,但是出现错误The file cannot be copied onto itself.
当我使用%userprofile%\Desktop\Out
和%userprofile%\Desktop\New Folder
运行脚本时,它运行平稳.
所以我的问题是,当您从公用根文件夹复制到另一个子文件夹时,为什么脚本会感到困惑?
@ECHO ON
FOR /r "%userprofile%\Desktop\Out" %%a IN (*.txt) DO copy "%%a" "%userprofile%\Desktop\New Folder"
pause
目标目录%userprofile%\Desktop\Out\test
是源的子目录,而%userprofile%\Desktop\New Folder
不是.
由于使用的是for /r
,因此在递归发生时,复制的文件将从较低的目录复制-从目标目录到目标目录.因此,文件将被复制到其自身上.
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
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.
这篇关于在FOR循环中复制可正常工作,但始终显示错误“无法将文件复制到自身上".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!