robocopy和源文件夹名称/编码

时间:2015-04-09 09:03:24

标签: robocopy

在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不能读出这个角色呢?

2 个答案:

答案 0 :(得分:2)

使用字符集1252适用于我的Windows 7机器。

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文件文本复制到新的批处理文件中才能使其正常工作。

答案 1 :(得分:0)

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