Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by Your Mother (Archbishop)
on Dec 12, 2015 at 16:12 UTC ( [id://1150119]=note: print w/replies, xml ) Need Help??


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

Most of the code is not being used at all… So the problem is probably that you are clobbering your hash somehow with the date stuff but you do not show it here. Or perhaps, judging by the modules you use, you aren’t creating the directories necessary before the move. Or maybe… this thing, File::PerlMove, is the culprit. Clobbering the move from File::Copy and having different usage. Try removing use File::PerlMove; and see if you get better error feedback.

I would also encourage you in another direction. This is simpler and has built in feedback for failures, which of course happens on my box.

use strictures; use Path::Tiny; my %files = ("e:/pervasive/staging/summit/C01" => "e:/pervasive/test/A +PEX012015/C01", "e:/pervasive/staging/summit/C02" => "e:/pervasive/test/A +PEX022015/C02", "e:/pervasive/staging/summit/C03" => "e:/pervasive/test/A +PEX032015/C03", ); for my $key ( keys %files ) { my $original = path($key); my $destination = $files{$key}; $original->move($destination); } __END__ moo@cow[88]~>perl pm/1150117.pl Error rename on 'e:/pervasive/staging/summit/C01' -> 'e:/pervasive/tes +t/APEX012015/C01': No such file or directory at pm/1150117.pl line 13 +.

Replies are listed 'Best First'.
Re^2: question regarding File::Copy, and hashes that contain file paths
by Leetsauce (Novice) on Dec 12, 2015 at 16:29 UTC
    Error rename on 'e:/pervasive/staging/summit/C01' -> 'e:/pervasive/tes +t/APEX012015/C01': No such file or directory at pm/1150117.pl line 13 +.
    This is now what I am running into. Any thoughts with dealing with this? It looks like it's searching for both the key -> value for the file path, or maybe I am misunderstanding the error.

      It is trying to do just what it says; move file1 (hash key) to file2 (value for that key). The -> is not code, just part of the message. So we’ll add a check for the original and a mkpath for the destination (if necessary) before doing the move; but it seems like you probably don’t have it unzipped the way you think–

      for my $key ( keys %files ) { my $original = path($key); die "There is no file $original" unless -f $original; my $destination = path($files{$key}); $destination->parent->mkpath unless -d $destination->parent; $original->move($destination); }
        Nah, it's unzipping appropriately(perfectly after applying some help I received here. thanks all!). The -> is referencing $zip, which as indicated by the code is the "get" for the archive. File::Copy will create the directory if necessary, so no need to mkdir. I *do* use dirmove, though, when taking it from the staging area to the production environment, after it has been renamed to the appropriate "APEX" prefix/suffix key/value combo. Basically, I'm unzipping payroll data for multiple companies, and trying to iterate through as much as I can without having to turn it into a c#, object-oriented executable because I am digging PERL so far, and want to continue to learn. Obviously, the code is newbish to the seasoned monk, but I'm learning at my own pace - in a business environment - while getting paid. Win/Win/Win =p Thanks for all your help!
Re^2: question regarding File::Copy, and hashes that contain file paths
by Leetsauce (Novice) on Dec 12, 2015 at 16:32 UTC
    Or, does this mean that the destination directory does not exist? In a separate decompression script I have (unzipped all of these files to the staging area) it creates the folder for me, so my assumption was that path would have that built in.

Log In?
Username:
Password:

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

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

    No recent polls found