in reply to File::Copy Problem on Mac OS X

Is that a direct copy and paste of your script? I doubt that this is a problem with File::Copy or using it on OS X. Are you remembering to put the arguments (given that they can contain spaces) in quotes? Take a look at this slight reworking of your example:
#!/usr/bin/perl use strict; use warnings; use File::Copy; my $source = $ARGV[0]; my $target = $ARGV[1]; copy($source, $target) or die "Can't copy files ($!) ($?)\n";
I created a file named 'testing spaces.txt' containing some text, and ran the script via
./copy.pl "testing spaces.txt" output.txt

If you have any further questions let us know

Hope this helps

Martin

Replies are listed 'Best First'.
Re^2: File::Copy Problem on Mac OS X
by ademmler (Novice) on Jun 03, 2008 at 11:59 UTC
    hi, thanks for your reply to all of you.

    The sample I gave was more for testing. In my real project I get the source url from a database.
    I pass them also quoated to copy(), but I always get this error ($!): (No such file or directory)

    If I print source and target URL to check if they are quoted I get:
    source: '/Users/ademmler/testing mit leerzeichen/myfile.pdf'
    target: '/Users/wfdata/myfile.pdf'

    I have tried to use singel and double quotes . . . no change.
    Mac OS X escapes the blank with \ and if I pass the path to my above testscript like this it works also. But if I try to add a \ via regex into the URL it does not work . . .

    Regards Alex
      ademmler,

      Firstly, these are not URLs the are paths to files.

      Secondly, are you sure you have permissions to read from/write to the source file and target directory? Please show us the code you are actually using, and how you are calling it. Have you tried quoting the parameters you are passing to the copy command?
      #!/usr/bin/perl use strict; use warnings; use File::Copy; my $source = $ARGV[0]; my $target = $ARGV[1]; copy("$source", "$target") or die "Can't copy files ($!)\n"
      Update: Fixed typo, reworded last sentence. Hope this helps

      Martin
        eh? "$source" creates a string that's a copy of $source. Why would you do that? Not only does @ARGV contain strings, this will happen implicitly if copy requires them to be strings.
        Hi - thank you all again.

        #Firstly, these are not URLs the are paths to files.
        Yeah you are right -sorry for using the wrong wording.

        #Secondly, are you sure you have permissions to read from/write to the source file and target directory?
        Yes I am, I can copy them from the shell . . .

        #Please show us the code you are actually using, and how you are calling it.
        Sorry, I cant - It is one line within a complete project with Database, daemons, WebGUIs etc. . .
        to big, therefore I have provided the stripped down sample file.

        #Have you tried quoting the parameters you are passing to the copy command?
        Yes - without succsess . . .

        Seems like there is a difference in my File::Copy from Perl 5.8.6 and the one from perl 5.10
        We are just checking this . . . Regards Alex