in reply to Remove Read-Only using xcopy

I think your "$out_dir/" is causing problems as Windows (and thus xcopy) uses forward slash, not backward slash as the directory character.

Try this - it worked for me:

system('xcopy', "\"$und_db\"", "\"$out_dir\\\"", '/r', '/y', '/i');

Replies are listed 'Best First'.
Re^2: Remove Read-Only using xcopy
by Anonymous Monk on Jun 15, 2009 at 20:05 UTC
    Thanks for the tip, but it still didn't copy the file =(. The only feedback I get is "0 File(s) copied" before the script continues to run (and crashes when it can't find the copied file). I debugged the two variables right before the function call and they contained the correct values. This one line of code is the only change to the script, which worked for weeks until the read-only problem showed up. Still stumped as to why it doesn't copy while the manually typed command does.
      Do you have a backslash between the drive letter and your first directory (d:\basedir ...). In your example, you don't and when I try xcopy without that slash, I get "0 files copied). When I put the slash in, it works.

      {C} > ls Directory of C:\Documents and Settings\Administrator\My Documents\tmp [.] [..] test.txt 1 File(s) 0 bytes {C} > xcopy "c:Documents and Settings\Administrator\My Documents\tmp\t +est.txt" "c:Documents and Settings\Administrator\My Documents\tmp\foo +\" File not found - test.txt 0 File(s) copied {C} > xcopy "c:\Documents and Settings\Administrator\My Documents\tmp\ +test.txt" "c:\Documents and Settings\Administrator\My Documents\tmp\f +oo\" C:\Documents and Settings\Administrator\My Documents\tmp\test.txt 1 File(s) copied {C} > ls Directory of C:\Documents and Settings\Administrator\My Documents\tmp [.] [..] [foo] test.txt 1 File(s) 0 bytes {C} > ls fool Directory of C:\Documents and Settings\Administrator\My Documents\tmp +\foo [.] [..] test.txt 1 File(s) 0 bytes
      Then using Perl:

      #!/usr/bin/perl use strict; my $und_db = "C:\\Documents and Settings\\Administrator\\My Documents\ +\tmp\\test.txt"; my $out_dir = "C:\\Documents and Settings\\Administrator\\My Documents +\\tmp\\foo"; system('xcopy', "\"$und_db\"", "\"$out_dir\\\"", '/r', '/y', '/i');
      And successful output:

      {C} > test C:\Documents and Settings\Administrator\My Documents\tmp\test.txt 1 File(s) copied {C} > ls foo Directory of C:\Documents and Settings\Administrator\My Documents\tmp +\foo [.] [..] test.txt 1 File(s) 0 bytes