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

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


当前回答

如果您可以使用Bash,那么可以简单地使用带有递归选项的以下命令。

cp -r "C:\Users\sourceFolder\." "C:\Users\destinationFolder"

这将复制所有文件和文件夹包含在sourceFolder内destincationFolder

其他回答

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

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

例子:

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 /s c:\source d:\target时,在c:\source和d:\target周围加上"",否则你会得到错误。

如果路径中有空格,即:

"C:\Some Folder\*.txt"

但如果你有:

C:\SomeFolder\*.txt
@echo off

rem The * at the end of the destination file is to avoid File/Directory Internal Question.

rem You can do this for each especific file. (Make sure you already have permissions to the path)
xcopy /Y "\\Oldeserver\storage\data\MyFile01.txt" "\\New server\storage\data\MyFile01.txt"*
pause

rem You can use "copy" instead of "xcopy "for this example.

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。

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