批处理文件将文件从一个文件夹复制到另一个文件夹。

时间:2021-07-25 01:49:58

I have a storage folder on a network in which all users will store their active data on a server. Now that server is going to be replaced by a new one due to place problem so I need to copy sub folders files from the old server storage folder to new server storage folder. I have below ex:

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

from \Oldeserver\storage\data & files to \New server\storage\data & files.

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

7 个解决方案

#1


357  

xcopy.exe is definitely your friend here. It's built into Windows, so its cost is nothing.

选择复制文件。exe肯定是你的朋友。它是装在窗户里的,所以它的成本是零。

Just xcopy /s c:\source d:\target

只有xcopy /s c:\source d:\target。

You'd probably want to tweak a few things; some of the options we also add include these:

你可能想要调整一些东西;我们还增加了一些选项,包括:

  • /s/e - recursive copy, including copying empty directories.
  • /s/e -递归拷贝,包括复制空目录。
  • /v - add this to verify the copy against the original. slower, but for the paranoid.
  • /v -添加这个以验证副本与原件。更慢,但对偏执狂来说。
  • /h - copy system and hidden files.
  • /h -复制系统和隐藏文件。
  • /k - copy read-only attributes along with files. otherwise, all files become read-write.
  • /k -复制只读属性和文件。否则,所有文件都将成为读写。
  • /x - if you care about permissions, you might want /o or /x.
  • /x -如果您关心权限,您可能需要/o或/x。
  • /y - don't prompt before overwriting existing files.
  • /y -在覆盖现有文件之前不要提示。
  • /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.
  • /z -如果你认为复制可能失败,你想重新启动它,就用这个。它在每个文件上都放置一个标记作为副本,这样您就可以重新运行xcopy命令以从它停止的地方恢复。

If you think the xcopy might fail partway through (like when you are copying over a flaky network connection), or that you have to stop it and want to continue it later, you can use xcopy /s/z c:\source d:\target.

如果您认为xcopy可能会失败(比如当您在一个不稳定的网络连接上复制时),或者您必须停止它并希望稍后继续它,您可以使用xcopy /s/ zc:\source d:\target。

Hope this helps.

希望这个有帮助。

#2


41  

Just to be clear, when you use xcopy /s c:\source d:\target, put "" around the c:\source and d:\target,otherwise you get error.

当你使用xcopy /s c:\source d:\target,把“”放在c:\source和d:\target,否则你会出错。

ie if there are spaces in the path ie if you have:

如果路径中有空格(如果有):

"C:\Some Folder\*.txt"

but not required if you have:

但如果你有:

C:\SomeFolder\*.txt

#3


34  

My favorite one to backup data is:

我最喜欢的备份数据是:

ROBOCOPY "C:\folder" "C:\new_folder" /mir

/mir is for mirror. You can also use /mov to move files. It reproduce the exact same folder. It can delete/overwrite files as needed. Works great for me. It's faster than xcopy / copy. It's built in Windows as well.

/米尔是镜子。你也可以使用/mov移动文件。它复制了完全相同的文件夹。它可以根据需要删除/覆盖文件。工作非常适合我。它比xcopy / copy快。它也建在窗户上。

Source: http://technet.microsoft.com/en-us/library/cc733145.aspx

来源:http://technet.microsoft.com/en-us/library/cc733145.aspx

#4


17  

You may want to take a look at XCopy or RoboCopy which are pretty comprehensive solutions for nearly all file copy operations on Windows.

你可能想看一下XCopy或RoboCopy,这是几乎所有文件拷贝操作在Windows上的非常全面的解决方案。

#5


11  

To bypass the 'specify a file name or directory name on the target (F = file, D = directory)?' prompt with xcopy, you can do the following...

要绕过“指定目标上的文件名或目录名(F = file, D =目录)?”用xcopy提示,您可以执行以下操作…

echo f | xcopy /f /y srcfile destfile

echo f | xcopy /f /y srcfile destfile。

or for those of us just copying large substructures/folders:

或者我们这些人只是复制大型的子结构/文件夹:

use /i which specifies destination must be a directory if copying more than one file

如果复制多个文件,则使用/i指定目的地必须是一个目录。

#6


1  

if you want to copy file not using absolute path, relative path in other words:

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

don't forget to write antislash in the path AND NOT slash (^^)

别忘了写信antislash的路径,而不是削减(^ ^)

example :

例子:

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

PS: absolute path can be retrieved use these wildcards called "batch parameters"

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"

check documentation here about copy : https://technet.microsoft.com/en-us/library/bb490886.aspx

在这里查看有关复制的文档:https://technet.microsoft.com/en-us/library/bb490886.aspx。

and also here for batch parameters documentation: https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true

这里也有批处理参数文档:https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/。

#7


0  

Look at rsync based Windows tool NASBackup. It will be a bonus if you are acquainted with rsync commands.

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

#1


357  

xcopy.exe is definitely your friend here. It's built into Windows, so its cost is nothing.

选择复制文件。exe肯定是你的朋友。它是装在窗户里的,所以它的成本是零。

Just xcopy /s c:\source d:\target

只有xcopy /s c:\source d:\target。

You'd probably want to tweak a few things; some of the options we also add include these:

你可能想要调整一些东西;我们还增加了一些选项,包括:

  • /s/e - recursive copy, including copying empty directories.
  • /s/e -递归拷贝,包括复制空目录。
  • /v - add this to verify the copy against the original. slower, but for the paranoid.
  • /v -添加这个以验证副本与原件。更慢,但对偏执狂来说。
  • /h - copy system and hidden files.
  • /h -复制系统和隐藏文件。
  • /k - copy read-only attributes along with files. otherwise, all files become read-write.
  • /k -复制只读属性和文件。否则,所有文件都将成为读写。
  • /x - if you care about permissions, you might want /o or /x.
  • /x -如果您关心权限,您可能需要/o或/x。
  • /y - don't prompt before overwriting existing files.
  • /y -在覆盖现有文件之前不要提示。
  • /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.
  • /z -如果你认为复制可能失败,你想重新启动它,就用这个。它在每个文件上都放置一个标记作为副本,这样您就可以重新运行xcopy命令以从它停止的地方恢复。

If you think the xcopy might fail partway through (like when you are copying over a flaky network connection), or that you have to stop it and want to continue it later, you can use xcopy /s/z c:\source d:\target.

如果您认为xcopy可能会失败(比如当您在一个不稳定的网络连接上复制时),或者您必须停止它并希望稍后继续它,您可以使用xcopy /s/ zc:\source d:\target。

Hope this helps.

希望这个有帮助。

#2


41  

Just to be clear, when you use xcopy /s c:\source d:\target, put "" around the c:\source and d:\target,otherwise you get error.

当你使用xcopy /s c:\source d:\target,把“”放在c:\source和d:\target,否则你会出错。

ie if there are spaces in the path ie if you have:

如果路径中有空格(如果有):

"C:\Some Folder\*.txt"

but not required if you have:

但如果你有:

C:\SomeFolder\*.txt

#3


34  

My favorite one to backup data is:

我最喜欢的备份数据是:

ROBOCOPY "C:\folder" "C:\new_folder" /mir

/mir is for mirror. You can also use /mov to move files. It reproduce the exact same folder. It can delete/overwrite files as needed. Works great for me. It's faster than xcopy / copy. It's built in Windows as well.

/米尔是镜子。你也可以使用/mov移动文件。它复制了完全相同的文件夹。它可以根据需要删除/覆盖文件。工作非常适合我。它比xcopy / copy快。它也建在窗户上。

Source: http://technet.microsoft.com/en-us/library/cc733145.aspx

来源:http://technet.microsoft.com/en-us/library/cc733145.aspx

#4


17  

You may want to take a look at XCopy or RoboCopy which are pretty comprehensive solutions for nearly all file copy operations on Windows.

你可能想看一下XCopy或RoboCopy,这是几乎所有文件拷贝操作在Windows上的非常全面的解决方案。

#5


11  

To bypass the 'specify a file name or directory name on the target (F = file, D = directory)?' prompt with xcopy, you can do the following...

要绕过“指定目标上的文件名或目录名(F = file, D =目录)?”用xcopy提示,您可以执行以下操作…

echo f | xcopy /f /y srcfile destfile

echo f | xcopy /f /y srcfile destfile。

or for those of us just copying large substructures/folders:

或者我们这些人只是复制大型的子结构/文件夹:

use /i which specifies destination must be a directory if copying more than one file

如果复制多个文件,则使用/i指定目的地必须是一个目录。

#6


1  

if you want to copy file not using absolute path, relative path in other words:

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

don't forget to write antislash in the path AND NOT slash (^^)

别忘了写信antislash的路径,而不是削减(^ ^)

example :

例子:

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

PS: absolute path can be retrieved use these wildcards called "batch parameters"

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"

check documentation here about copy : https://technet.microsoft.com/en-us/library/bb490886.aspx

在这里查看有关复制的文档:https://technet.microsoft.com/en-us/library/bb490886.aspx。

and also here for batch parameters documentation: https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true

这里也有批处理参数文档:https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/。

#7


0  

Look at rsync based Windows tool NASBackup. It will be a bonus if you are acquainted with rsync commands.

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