简体   繁体   English

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

[英]Windows cmd shell xcopy to network directory doesn't work

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

( /d for only new files, /i because source is a dir, /s for all the subdirs and files, /q just to supress the copy text) /d仅用于新文件, /i因为source是dir, /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 eg "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?

Skip xcopy and use robocopy with the /E flag instead. 跳过xcopy并使用带有/ E标志的robocopy。 It's built into all recent versions of Windows. 它内置于所有最新版本的Windows中。 Free download for XP. 免费下载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. 这会将“source”文件夹中的所有文件复制到尚未复制的“backup”文件夹中。

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

Robocopy must be better because it should create directories with the \\E switch. Robocopy必须更好,因为它应该使用\\ E开关创建目录。 No overwrites for files, just adds a file with extra letters or extension <> command. 没有覆盖文件,只需添加一个带有额外字母或扩展名<>命令的文件。 Still must defrag. 仍然必须碎片整理。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM