使用进度在 Windows 命令行上复制文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/58782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:15:48  来源:igfitidea点击:

Copy files on Windows Command Line with Progress

windowsbatch-filescripting

提问by adrian

I need to copy files using Windows command-line (available on XP Pro or later by default) and show progress during the process.

我需要使用 Windows 命令行(默认情况下在 XP Pro 或更高版本上可用)复制文件并在此过程中显示进度。

The progress indicator could be in a terminal or a GUI window. It is intended to be used during batch file scripting.

进度指示器可以在终端或 GUI 窗口中。它旨在用于批处理文件脚本。

回答by adrian

I used the copy command with the /z switch for copying over network drives. Also works for copying between local drives. Tested on XP Home edition.

我使用带有 /z 开关的 copy 命令通过网络驱动器进行复制。也适用于本地驱动器之间的复制。在 XP Home 版上测试。

回答by Kent Boogaart

robocopy:

机器人复制

Robocopy, or "Robust File Copy", is a command-linedirectory and/or file replication command. Robocopy functionally replaces Xcopy, with more options. It has been available as part of the Windows Resource Kitstarting with Windows NT 4.0, and was first introduced as a standard feature in Windows Vistaand Windows Server 2008. The command is robocopy...

Robocopy或“强大的文件复制”,是命令行目录和/或文件复制命令。Robocopy 在功能上取代了Xcopy,具有更多选项。从 Windows NT 4.0 开始,它已作为Windows 资源工具包的一部分提供,并首次作为Windows VistaWindows Server 2008 中的标准功能引入。命令是robocopy...

回答by npocmaka

The Esentutl/y option allows copyng (single) file files with progress bar like this :

ESENTUTL/ y选项允许copyng像这样的进度条(单)文件中的文件:

enter image description here

在此处输入图片说明

the command should look like :

该命令应如下所示:

esentutl /y "FILE.EXT" /d "DEST.EXT" /o

The command is available on every windows machine but the yoption is presented in windows vista. As it works only with single files does not look very useful for a small ones. Other limitation is that the command cannot overwrite files. Here'sa wrapper script that checks the destination and if needed could delete it (help can be seen by passing /h).

该命令在每台 Windows 机器上都可用,但该y选项在 windows vista 中提供。因为它只适用于单个文件,所以对于小文件来说看起来不是很有用。其他限制是该命令不能覆盖文件。这是一个检查目的地的包装脚本,如果需要可以删除它(通过传递可以看到帮助/h)。

回答by Iconiu

Some interesting timings regarding all these methods. If you have Gigabit connections, you should not use the /z flag or it will kill your connection speed. Robocopy or dism are the only tools that go full speed and show a progress bar. wdscase is for multicasting off a WDS server and might be faster if you are imaging 5+ computers. To get the 1:17 timing, I was maxing out the Gigabit connection at 920Mbps so you won't get that on two connections at once. Also take note that exporting the small wim index out of the larger wim file too longer than just copying the whole thing.

关于所有这些方法的一些有趣的时间安排。如果您有千兆连接,则不应使用 /z 标志,否则会降低连接速度。Robocopy 或 dism 是唯一可以全速运行并显示进度条的工具。wdscase 用于从 WDS 服务器多播,如果您要对 5 台以上计算机进行映像,速度可能会更快。为了获得 1:17 的时间,我以 920Mbps 的速度最大化了千兆连接,这样你就不会同时在两个连接上获得它。另请注意,从较大的 wim 文件中导出小 wim 索引的时间比仅复制整个内容的时间要长。

Model  Exe       OS       switches     index    size    time   link speed 
8760w  dism      Win8     /export-wim  index 1  6.27GB  2:21   link 1Gbps
8760w  dism      Win8     /export-wim  index 2  7.92GB  1:29   link 1Gbps
6305   wdsmcast  winpe32  /trans-file  res.RWM  7.92GB  6:54   link 1Gbps
6305   dism      Winpe32  /export-wim  index 1  6.27GB  2:20   link 1Gbps
6305   dism      Winpe32  /export-wim  index 2  7.92GB  1:34   link 1Gbps
6305   copy      Winpe32  /z           Whole    7.92GB  25:48  link 1Gbps
6305   copy      Winpe32  none         Wim      7.92GB  1:17   link 1Gbps
6305   xcopy     Winpe32  /z /j        Wim      7.92GB  23:54  link 1Gbps
6305   xcopy     Winpe32  /j           Wim      7.92GB  1:38   link 1Gbps
6305   VBS.copy  Winpe32               Wim      7.92    1:21   link 1Gbps
6305   robocopy  Winpe32               Wim      7.92    1:17   link 1Gbps

If you don't have robocopy.exe available, why not run it from the network share you are copying your files from? In my case, I prefer to do that so I don't have to rebuild my WinPE boot.wim file every time I want to make a change and then update dozens of flash drives.

如果没有 robocopy.exe 可用,为什么不从要从中复制文件的网络共享运行它呢?就我而言,我更喜欢这样做,这样我就不必每次想要进行更改然后更新数十个闪存驱动器时都重新构建我的 WinPE boot.wim 文件。

回答by Gulzar Nazim

This technet linkhas some good info for copying large files. I used an exchange server utility mentioned in the article which shows progress and uses non buffered copy functions internally for faster transfer.

这个技术网链接有一些复制大文件的好信息。我使用了文章中提到的交换服务器实用程序,该实用程序显示进度并在内部使用非缓冲复制功能以加快传输速度。

In another scenario, I used robocopy. Robocopy GUImakes it easier to get your command line options right.

在另一个场景中,我使用了 robocopy。Robocopy GUI使您可以更轻松地正确设置命令行选项。

回答by djangofan

Here is the script I use:

这是我使用的脚本:

@ECHO off
SETLOCAL ENABLEDELAYEDEXPANSION
mode con:cols=210 lines=50
ECHO Starting 1-way backup of MEDIA(M:) to BACKUP(G:)...
robocopy.exe M:\ G:\ *.* /E /PURGE /SEC /NP /NJH /NJS /XD "$RECYCLE.BIN" "System Volume Information" /TEE /R:5 /COPYALL /LOG:from_M_to_G.log
ECHO Finished with backup.
pause

回答by Josef

You could easily write a program to do that, I've got several that I've written, that display bytes copied as the file is being copied. If you're interested, comment and I'll post a link to one.

你可以很容易地编写一个程序来做到这一点,我已经写了几个,显示复制文件时复制的字节。如果您有兴趣,请发表评论,我会发布一个链接。