0

Is it possible to copy files from a folder to another folder with read-only attribute enabled? I mean the destination folder is read-only.

Thanks

mpakbaz
  • 486
  • 1
  • 6
  • 20

2 Answers2

1

Yes, that is possible on Windows 7...

repro:

>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
rene
  • 41,474
  • 78
  • 114
  • 152
  • Thanks for the answer, however my problem is in team foundation, since in my repository all the files are read-only by default as they are downloaded from the server. My intention was to copy output of one project to another folder in other project in solution, however I don't no matter how I try xcopy from the post build actions I get an error like "exited with code 4" I realized that the issue is because the destination folder is read-only. btw, your code is working fine in an ordinary case as you send it but for my case no. anyway thanks for the help. – mpakbaz Oct 07 '13 at 12:24
  • If you started with that... you did try using the [](http://msdn.microsoft.com/en-us/library/vstudio/3e54c37h.aspx) task from msbuild? What does the path look like you are copying to? use a [`/v:diag`](http://msdn.microsoft.com/en-us/library/vstudio/ms164311.aspx) in your tfs build to obtain detailed logging... – rene Oct 07 '13 at 12:52
0

use /R to override readonly as following

xcopy /R <source> <destination>
Firas Nizam
  • 1,392
  • 12
  • 7