【问题标题】:robocopy and source folder name/encodingrobocopy 和源文件夹名称/编码
【发布时间】:2020-03-07 02:38:12
【问题描述】:

在 Windows 8 上,我正在尝试使用 robocopy 复制文件夹

robocopy /MIR /E /DCOPY:T /s "c:\test\xupdate can’t be deployed" "c:\test\out\"

但它失败了:

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows
-------------------------------------------------------------------------------

  Started : 9. april 2015 10:56:35
   Source : C:\test\xupdate canÈÃÍt be deployed
     Dest : C:\test\out\

    Files : *.*

  Options : *.* /S /DCOPY:T /COPY:DAT /PURGE /MIR /R:1000000 /W:30

2015/04/09 10:59:44 ERROR 2 (0x00000002) Accessing Source Directory C:\test\xupdate canÈÃÍt be deployed

The system cannot find the file specified.

所以问题显然是源文件夹名称中的 字符。但是为什么 robocopy 不能读取那个字符呢?

【问题讨论】:

    标签: robocopy


    【解决方案1】:

    在我的 windows 7 机器上使用字符集 1252。

    chcp 1252 
    
    robocopy /MIR /E /DCOPY:T /s "c:\test\xupdate can't be deployed" "c:\test\out"
    

    根据 Notepad++ 对 .bat 文件进行编码:

    不带 BOM 的 UTF-8

    结果:

    -------------------------------------------------------------------------------
       ROBOCOPY     ::     Robust File Copy for Windows
    
    -------------------------------------------------------------------------------
    
      Started : Fri Aug 28 12:35:13 2015
    
       Source : c:\test\xupdate can't be deployed\
         Dest : c:\test\out\
    
        Files : *.*
    
      Options : *.* /S /COPY:DAT /DCOPY:T /PURGE /MIR /R:1000000 /W:30
    
    ------------------------------------------------------------------------------
    
                               1    c:\test\xupdate can't be deployed\
    
    ------------------------------------------------------------------------------
    
                   Total    Copied   Skipped  Mismatch    FAILED    Extras
        Dirs :         1         0         1         0         0         0
       Files :         1         0         1         0         0         0
       Bytes :       245         0       245         0         0         0
       Times :   0:00:00   0:00:00                       0:00:00   0:00:00
    
       Ended : Fri Aug 28 12:35:13 2015
    

    我用windows记事本创建了bat文件。

    不幸的是,在创建具有相同编码的新 .bat 文件时,我无法重新创建上述内容。无论编码如何,Robocopy 都会失败,我得到的最好的结果是:

    -------------------------------------------------------------------------------
       ROBOCOPY     ::     Robust File Copy for Windows
    
    -------------------------------------------------------------------------------
    
      Started : Fri Aug 28 12:37:20 2015
    
       Source : c:\test\xupdate can't be deployed\
         Dest : c:\test\out\
    
        Files : *.*
    
      Options : *.* /COPY:DAT /R:1000000 /W:30
    
    ------------------------------------------------------------------------------
    
    2015/08/28 12:37:20 ERROR 2 (0x00000002) Accessing Source Directory c:\test\xupd
    ate can't be deployed\
    The system cannot find the file specified.
    

    我必须将原始 .bat 文件文本复制到一个新的批处理文件中才能使其工作。

    【讨论】:

    • 谢谢!我在 Win7 机器上遇到了类似的问题,文件路径有时用德语 ü 和 ö 命名(u-Umlaut,o-Umlaut)。 chcp 1252 为我解决了这个问题。
    【解决方案2】:

    如果您正在制作批处理命令文件并使用 UTF-8 编码保存文件,请在批处理文件的第一行使用chcp 65001。 我来自捷克共和国,有类似的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多