in reply to Re^2: 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.

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
  • Comment on Re^3: question regarding File::Copy, and hashes that contain file paths
  • Download Code

Replies are listed 'Best First'.
Re^4: question regarding File::Copy, and hashes that contain file paths
by Leetsauce (Novice) on Dec 16, 2015 at 00:23 UTC
    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.
Re^4: question regarding File::Copy, and hashes that contain file paths
by Leetsauce (Novice) on Dec 17, 2015 at 21:13 UTC
    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
        This is exactly what I needed. I ended up using:
        my $base_path = 'e:/iwantfileshere'; dirmove($from,$to) if -e $base_path;
        Thank you for your help!