【问题标题】:Copy to read-only folder using xcopy使用 xcopy 复制到只读文件夹
【发布时间】:2013-10-07 08:57:30
【问题描述】:

是否可以将文件从文件夹复制到另一个启用只读属性的文件夹?我的意思是目标文件夹是只读的。

谢谢

【问题讨论】:

  • 是通过设置属性只读还是通过ACL只读?
  • 我在问题中提到的属性

标签: copy readonly xcopy


【解决方案1】:

是的,这在 Windows 7 上是可能的...

再现:

>cd \windows
>dir *.ini
 Volume in drive C has no label.
 Volume Serial Number is xxxxxxx

 Directory of C:\Windows

26-04-2008  21:42                25 cdplayer.ini
11-08-2009  22:18                 0 iPlayer.INI
10-06-2009  22:36             1.405 msdfmap.ini
22-09-2009  18:00               162 ODBC.INI
31-10-2009  22:35               232 ODBCINST.INI
10-06-2009  23:08               219 system.ini
15-05-2013  21:03                39 vbaddin.ini
13-11-2012  23:18               219 win.ini
               8 File(s)          2.301 bytes
               0 Dir(s)  xxxxxx bytes free

>mkdir c:\xcp
>attrib +R c:\xcp
>attrib c:\xcp
     R       C:\xcp
>xcopy "*.ini" "c:\xcp"
C:cdplayer.ini
C:iPlayer.INI
C:msdfmap.ini
C:ODBC.INI
C:ODBCINST.INI
C:system.ini
C:vbaddin.ini
C:win.ini
8 File(s) copied

>dir c:\xcp
 Volume in drive C has no label.
 Volume Serial Number is XXXXXXXX

 Directory of c:\xcp

07-10-2013  11:27    <DIR>          .
07-10-2013  11:27    <DIR>          ..
26-04-2008  21:42                25 cdplayer.ini
11-08-2009  22:18                 0 iPlayer.INI
10-06-2009  22:36             1.405 msdfmap.ini
22-09-2009  18:00               162 ODBC.INI
31-10-2009  22:35               232 ODBCINST.INI
10-06-2009  23:08               219 system.ini
15-05-2013  21:03                39 vbaddin.ini
13-11-2012  23:18               219 win.ini
               8 File(s)          2.301 bytes
               2 Dir(s)   xxxxxxxxxxxxx bytes free

【讨论】:

  • 感谢您的回答,但是我的问题出在团队基础上,因为在我的存储库中,所有文件默认都是只读的,因为它们是从服务器下载的。我的意图是将一个项目的输出复制到解决方案中另一个项目中的另一个文件夹,但是无论我如何从构建后操作中尝试 xcopy,我都会收到类似“退出代码 4”这样的错误,我意识到这个问题是因为目标文件夹是只读的。顺便说一句,您的代码在发送时在普通情况下运行良好,但对于我的情况没有。无论如何感谢您的帮助。
  • 如果你从那个开始......你确实尝试过使用 msbuild 中的<copy> 任务?您要复制到的路径是什么样的?在您的 tfs 构建中使用 /v:diag 来获取详细的日志记录...
【解决方案2】:

使用 /R 覆盖只读如下

xcopy /R <source> <destination>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-17
    • 2014-04-04
    • 1970-01-01
    • 2018-06-25
    • 1970-01-01
    • 2018-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多