在 FOR 循环中复制有效,但一直给出错误"The file cannot be copied onto itself"



所以当我使用dirs复制%userprofile%DesktopOut%userprofile%DesktopOuttest时,.txt被复制了,但是我得到了错误The file cannot be copied onto itself.

当我用%userprofile%DesktopOut%userprofile%DesktopNew Folder运行脚本时,它运行顺利。

所以我的问题是为什么当你从一个共同的根文件夹复制到不同的子文件夹时,脚本会感到困惑?

@ECHO ON
FOR /r "%userprofile%DesktopOut" %%a IN (*.txt) DO copy "%%a" "%userprofile%DesktopNew Folder"
pause

目的目录%userprofile%DesktopOuttest是源目录的子目录,而%userprofile%DesktopNew Folder不是。

由于您使用的是for /r,因此当递归发生时,复制的文件将从下目录复制—从目标目录复制到目标目录。因此,一个文件将被复制到自己上面。

相关内容

最新更新