in reply to Re^3: file is not getting copied
in thread file is not getting copied

my $copy_from = "C:/Users/Admin/Desktop/Staples files/readfile.txt";
This is the source

Output message is
C:\Users\Admin>perl C:\Users\Admin\Desktop\perl_programs\copyfn.pl Can't copy because: No such file or directory at C:\Users\Admin\Desktop\perl_programs\copyfn.pl line 7

So why is Perl looking for readfile.txt in this location ? Obviously, readfile.txt is not located in perl_programs. When source path is provided, Perl should look into that source path.
Please explain

Replies are listed 'Best First'.
Re^5: file is not getting copied
by Corion (Patriarch) on Jul 17, 2011 at 18:22 UTC
    ... at C:\Users\Admin\Desktop\perl_programs\copyfn.pl line 7

    means that the error was found when Perl ran the line number 7 in the named program. This has nothing to do with $copy_from or $copy_to, but it helps you to know what command failed.

      So my confusion is how to resolve this problem ? I am giving source and destination properly and files do exist in specified location. I am using copy function properly. SO why is it not working ?

      Thanks

        If it is not working, at least one of your assumptions is wrong. Test them one by one:

        # Test if $copy_from exists: -f $copy_from or die "File '$copy_from' does not exist"; # Test if the directory for $copy_to exists: use File::Basename; my $target_dir = dirname($copy_to); -d $target_dir or die "Target directory '$target_dir' does not exist";
        #!/usr/bin/perl -- use strict; use warnings; use Path::Class; ## exists #~ my $file = q[C:\Program Files\Mozilla Firefox\chrome\icons\default\ +chatzilla-window.ico]; my $file = q[C:\Program Files\Mozilla Firefox\chrome2\icons2\default2\ +chatzilla-window2.ico]; $file = file($file); while( not -r $file ){ printf "($file):\n(%d)(%s)\n(%d)(%s)\n\n", $!,$!,$^E,$^E; $file = $file->parent; } print "$file\n\n"; __END__ (C:\Program Files\Mozilla Firefox\chrome2\icons2\default2\chatzilla-wi +ndow2.ico): (2)(No such file or directory) (3)(The system cannot find the path specified) (C:\Program Files\Mozilla Firefox\chrome2\icons2\default2): (2)(No such file or directory) (3)(The system cannot find the path specified) (C:\Program Files\Mozilla Firefox\chrome2\icons2): (2)(No such file or directory) (3)(The system cannot find the path specified) (C:\Program Files\Mozilla Firefox\chrome2): (2)(No such file or directory) (2)(The system cannot find the file specified) C:\Program Files\Mozilla Firefox