2016-09-19 21 views
1

所以,當我複製使用迪爾斯%userprofile%\Desktop\Out%userprofile%\Desktop\Out\test.txt被複制,但是我得到的錯誤The file cannot be copied onto itself.複製在FOR循環的作品,但一直給錯誤「的文件不能被複制到自身」

當我運行與%userprofile%\Desktop\Out和腳本運行順利。

所以我的問題是爲什麼當你從一個普通的根文件夾複製到不同的子文件夾時,腳本會感到困惑?

@ECHO ON 
FOR /r "%userprofile%\Desktop\Out" %%a IN (*.txt) DO copy "%%a" "%userprofile%\Desktop\New Folder" 
pause 
+0

當'%userprofile%\ Desktop \ Out \ test'中已經存在'* .txt'文件時,會出現這種情況,這些文件被'for userRFile%\ Desktop \ Out「枚舉出來...... – aschipfl

回答

2

目標目錄%userprofile%\Desktop\Out\test是源的子目錄,而不是。

由於您使用的是for /r,所以複製的文件將在發生遞歸時從較低的目錄複製 - 從目標目錄INTO到目標目錄。因此,文件將被複制到其自身。