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

Re^2: question regarding File::Copy, and hashes that contain file paths

by Leetsauce (Novice)
on Dec 12, 2015 at 16:43 UTC ( [id://1150123]=note: print w/replies, xml ) Need Help??


in reply to Re: question regarding File::Copy, and hashes that contain file paths
in thread question regarding File::Copy, and hashes that contain file paths

Yes they are directories, and they have things inside them as well. Think that could be causing an issue? The for each that was posted before yours basically had the same result, with exception it was then telling me the new directory didn't exist.
  • Comment on Re^2: question regarding File::Copy, and hashes that contain file paths

Replies are listed 'Best First'.
Re^3: question regarding File::Copy, and hashes that contain file paths
by poj (Abbot) on Dec 12, 2015 at 18:18 UTC
    Yes they are directories, and they have things inside them as well.

    Take a look at File::Copy::Recursive

    #!/usr/bin/perl use strict; use File::Copy::Recursive qw(dircopy dirmove); use Time::Piece; my $MDY = localtime->mdy(''); print "$MDY \n\n"; my $src = 'e:/pervasive/staging/summit/'; my $dest = 'e:/pervasive/test/'; my @f = qw(01 02 03 04 05 06 07 08 30 40 41 42 43 44 44 50 80 85 99 ); my %compHash; for my $n (@f[0]){ # replace with @f if it works for first $compHash{'C'.$n} = 'APEX'.$n.'2015/C'.$n; $compHash{'C'.$n.'-2015'} = 'APEX'.$n.'2015/CSW'; }; foreach my $key (sort keys %compHash) { my $from = $src.$key; my $to = $dest.$compHash{$key}; print "Moving $from $to\n"; dirmove ( $from,$to ) or die "$!"; }
    poj
      I used the hash from this, ultimately. It worked perfectly. I try to stay away from hardcoding stuff as much as I can, but in this situation it was absolutely merited. The way you did this was perfect for me, and I so greatly appreciate your help with this.
      How would I check to see if the file exists with this? So we have @f defined as the list of company numbers (C## - which represents company ID ) and for each of those, we're renaming the directory and moving it, but it breaks when it hits the key that does not exist in the folder (company 6 is not inside my zip, but it is a possible company that CAN be in the zip) so I'm looking for a quick way to check if the actual file, that corresponds with the key in our @f, even exists because if it doesn't, i need to skip it. I think this will involve next, or exists, or maybe both. Any insight?

        see file exists test -e -X

        foreach my $key (sort keys %compHash) { my $from = $src.$key; next unless (-e $from); . .
        poj
Re^3: question regarding File::Copy, and hashes that contain file paths
by flexvault (Monsignor) on Dec 12, 2015 at 17:03 UTC

    Leetsauce,

    You can test for file or directory by:

    if ( -f $file ) { .... } ## $file is a file elsif ( -d $file ) { ... } ## also could use '_' for speed else { ,,, } ## Not what we're looking for
    Also you may wish to look at 'glob' for getting information about directory contents ( files and/or directories ).

    Good Luck...Ed

    "Well done is better than well said." - Benjamin Franklin

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1150123]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-04-23 20:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found