我在网络上有一个存储文件夹,所有用户将在服务器上存储他们的活动数据。现在,由于位置问题,服务器将被一个新的服务器所取代,所以我需要将子文件夹文件从旧的服务器存储文件夹复制到新的服务器存储文件夹。我有以下例子:

从\Oldeserver\存储\数据和文件到\新服务器\存储\数据和文件。


当前回答

Xcopy.exe绝对是你的朋友。 它内置在Windows中,所以它的成本是零。

xcopy /s c:\source d:\target

你可能想要调整一些东西;我们还添加了以下选项:

/s/e - recursive copy, including copying empty directories. /v - add this to verify the copy against the original. slower, but for the paranoid. /h - copy system and hidden files. /k - copy read-only attributes along with files. otherwise, all files become read-write. /x - if you care about permissions, you might want /o or /x. /y - don't prompt before overwriting existing files. /z - if you think the copy might fail and you want to restart it, use this. It places a marker on each file as it copies, so you can rerun the xcopy command to pick up from where it left off.

如果你认为xcopy可能会中途失败(比如当你在一个脆弱的网络连接上复制时),或者你必须停止它并想稍后继续它,你可以使用xcopy /s/z c:\source d:\target。

其他回答

如果你不想用绝对路径复制文件,换句话说,相对路径:

不要忘记在路径中加上反斜杠而不是斜杠

例子:

copy children-folder\file.something .\other-children-folder

PS:绝对路径可以使用这些称为“批处理参数”的通配符检索。

@echo off
echo %%~dp0 is "%~dp0"
echo %%0 is "%0"
echo %%~dpnx0 is "%~dpnx0"
echo %%~f1 is "%~f1"
echo %%~dp0%%~1 is "%~dp0%~1"

查看关于复制的文档:https://technet.microsoft.com/en-us/library/bb490886.aspx

这里还有批参数文档: https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true

你可能想看看XCopy或RoboCopy,它们是非常全面的解决方案,几乎适用于Windows上的所有文件复制操作。

看看基于rsync的Windows工具NASBackup。如果您熟悉rsync命令,这将是一个额外的奖励。

你可以使用esentutl复制(主要是大文件)的进度条:

esentutl /y "my.file" /d "another.file" /o

进度条看起来是这样的:

Xcopy.exe绝对是你的朋友。 它内置在Windows中,所以它的成本是零。

xcopy /s c:\source d:\target

你可能想要调整一些东西;我们还添加了以下选项:

/s/e - recursive copy, including copying empty directories. /v - add this to verify the copy against the original. slower, but for the paranoid. /h - copy system and hidden files. /k - copy read-only attributes along with files. otherwise, all files become read-write. /x - if you care about permissions, you might want /o or /x. /y - don't prompt before overwriting existing files. /z - if you think the copy might fail and you want to restart it, use this. It places a marker on each file as it copies, so you can rerun the xcopy command to pick up from where it left off.

如果你认为xcopy可能会中途失败(比如当你在一个脆弱的网络连接上复制时),或者你必须停止它并想稍后继续它,你可以使用xcopy /s/z c:\source d:\target。