运行批处理文件将“桌面”和“我的文档”备份到共享位置



我在域上有50台机器,我想把它们的桌面和我的文档文件夹备份到网络上的一个共享驱动器上。

我写了一个批处理文件,并通过GPO/schedule任务将其添加到所有计算机中。这对一些人来说是有效的但对一些人来说,它会弹出一个问题问他们是否不能创建目录或者是否为目录并要求提示"d"

请看看我在运行什么

ECHO off
mkdir "\ServLocal_Backup%username%Desktop"
mkdir "\ServLocal_Backup%username%My Documents"
xcopy "%userprofile%Desktop" "\ServLocal_Backup%username%Desktop" /E /Y /Q
xcopy "%userprofile%Documents" "\ServLocal_Backup%username%My Documents" /E /Y /Q
Exit

用更少的麻烦达到同样的目标的最好方法是什么?

是否有一种方法可以传递值d并在此代码中按enter键?

类型

xcopy /?

部分内容是

Copies files and directory trees.
NOTE: Xcopy is now deprecated, please use Robocopy.

同时还有/i开关

/I           If destination does not exist and copying more than one file,
             assumes that destination must be a directory.

指定文件名效果更好。

xcopy "%userprofile%Desktop*.*" "\ServLocal_Backup%username%Desktop*.*" /E /Y /Q
xcopy "%userprofile%Documents*.*" "\ServLocal_Backup%username%My Documents*.*" /E /Y /Q

robocopy /?

robocopy.doc

目标后面的反斜杠告诉xcopy目标是一个目录,这些目录将被自动创建。

在源文件夹上使用filespec

@echo off
xcopy "%userprofile%Desktop*.*" "\ServLocal_Backup%username%Desktop" /E /Y /Q
xcopy "%userprofile%Documents*.*" "\ServLocal_Backup%username%My Documents" /E /Y /Q

相关内容

最新更新