所以当我使用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
,因此当递归发生时,复制的文件将从下目录复制—从目标目录复制到目标目录。因此,一个文件将被复制到自己上面。