Windows cmd shell xcopy 到网络目录不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21041037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 11:15:01  来源:igfitidea点击:

Windows cmd shell xcopy to network directory doesn't work

windowsbatch-filexcopy

提问by Flyckten

Im trying to make a batch file that will copy all new files and folders from a source folder to an network directory. All the new subdirectories and new files should be copied (backup).

我正在尝试制作一个批处理文件,它将所有新文件和文件夹从源文件夹复制到网络目录。所有新的子目录和新文件都应该被复制(备份)。

My code:

我的代码:

xcopy "C:\Source" "T:\Backup" /d/i/s/q

xcopy "C:\Source" "T:\Backup" /d/i/s/q

(/dfor only new files, /ibecause source is a dir, /sfor all the subdirs and files, /qjust to supress the copy text)

/d仅对于新文件,/i因为 source 是一个目录,/s对于所有子目录和文件,/q只是为了抑制复制文本)

Source contains both subdirectories and files (.txt).

源包含子目录和文件 (.txt)。

The first run it copies Everything as it should. When I add a new .txt file to one of the existing subdirectories and run it again I get the message:

第一次运行时,它会按原样复制一切。当我将新的 .txt 文件添加到现有子目录之一并再次运行它时,我收到以下消息:

"An error occured when the file The directory is not empty. was being created. The folder "T:\Backup" could not be created. 0 files copied. (Translated from Swedish so not 100% original)

“当文件目录非空时发生错误。正在创建。无法创建文件夹“T:\Backup”。复制了 0 个文件。(从瑞典语翻译,所以不是 100% 原创)

The thing is when I try this command to a local source like e.g. "C:\test" and do the same procedure it works.

问题是当我尝试将此命令发送到本地源(例如“C:\test”)并执行相同的程序时。

Anyone who can understand why this doesn't work for the network drive? Should I try Another command such as robocopy?

谁能理解为什么这不适用于网络驱动器?我应该尝试另一个命令,例如 robocopy 吗?

回答by selbie

Skip xcopy and use robocopy with the /E flag instead. It's built into all recent versions of Windows. Free download for XP.

跳过 xcopy 并使用带有 /E 标志的 robocopy。它内置于所有最新版本的 Windows 中。XP免费下载。

Example:

例子:

robocopy c:\source T:\backup /E

That will copy all the files in the "source" folder to the "backup" folder that haven't been copied already.

这会将“源”文件夹中的所有文件复制到尚未复制的“备份”文件夹中。

And if you don't want to have the output shown on the console (equivalent to the /Q option in xcopy):

如果您不想在控制台上显示输出(相当于 xcopy 中的 /Q 选项):

robocopy c:\source T:\backup /E /LOG:nul

回答by Michael

Robocopy must be better because it should create directories with the \E switch. No overwrites for files, just adds a file with extra letters or extension <> command. Still must defrag.

Robocopy 必须更好,因为它应该使用 \E 开关创建目录。没有覆盖文件,只需添加一个带有额外字母或扩展名 <> 命令的文件。仍然必须进行碎片整理。

回答by spider

XCOPY "DRIVE LETTER:\windows.old\USERS" "\computername\D\NAME\" /D /E /C /R /I /K /Y /f

XCOPY "驱动器字母:\windows.old\USERS" "\computername\D\NAME\" /D /E /C /R /I /K /Y /f