Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Files copying from source to dest

by Ma (Novice)
on Nov 04, 2013 at 18:29 UTC ( #1061171=perlquestion: print w/ replies, xml ) Need Help??
Ma has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am trying to accomplish some csv files copying from source to destination. Here is my attempt and I have not been able to make it work as required. Any suggestions? Thanks
#!C:\Perl\bin\perl.exe use strict; use warnings; use Diagnostics; use File::Copy; use Cwd 'chdir'; my $source = "d:/Perl/Daily" unless $source; my $dest = "d:/Perl/Daily" unless $dest; chdir "$source" or die "Dying - can't cd to $source: $!\n"; $date = "1104"; system("md $date"); copy("AddressDevCHUBldgProj.csv", "$source/1031/");

Comment on Files copying from source to dest
Download Code
Re: Files copying from source to dest
by Old_Gray_Bear (Bishop) on Nov 04, 2013 at 19:20 UTC
    I have a few questions:
    1. What output did you expect? What did you actually get?
    2. What error(s) did you see? What message(s) did you get?
    3. What did you expect the call to the multi-device driver to do?

    You have not given me enough data to make even and uninformed guess.

    ----
    I Go Back to Sleep, Now.

    OGB

      I would like the cvs file to be copied to destination But the following error messages are coming when I run the program, the following error messages show up:
      Global symbol "$source" requires explicit package name at tt.txt line +8. Global symbol "$dest" requires explicit package name at tt.txt line 9. Global symbol "$date" requires explicit package name at tt.txt line 14 +. Global symbol "$date" requires explicit package name at tt.txt line 16 +. Execution of tt.txt aborted due to compilation errors.
      One thing I noticed that perl does not accept d:\Perl\Daily path but instead d:/Perl/Daily
        1. unless $source executes before my $source, thus the error
        2. $dest ditto
        3. no my $date anywhere
        4. ditto
Re: Files copying from source to dest
by atcroft (Monsignor) on Nov 04, 2013 at 19:24 UTC

    The error message you receive would be helpful; however, I did notice that in your copy() statement, you have $source/1031/ as your destination, suggesting that you hard-coded the date in originally, and now are failing because $source/$date is being created, but $source/1031 is the destination target.

    Hope that helps.

      Thank you. I posted the error message.
Re: Files copying from source to dest
by pvaldes (Chaplain) on Nov 05, 2013 at 21:17 UTC

    You can consider also to use the perl function mkdir instead the system call to md. See also File::Path

    consider also:

    if (-d $source){opendir, readdir, chdir... do something}

    instead

    chdir $source or die cant cd to the source; do something

    Because Daily could be also an archive

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1061171]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2014-07-31 06:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (245 votes), past polls