Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re^2: File::Copy - move() function corrupting files

by myelinviolin (Novice)
on Aug 25, 2014 at 16:19 UTC ( #1098532=note: print w/replies, xml ) Need Help??

in reply to Re: File::Copy - move() function corrupting files
in thread File::Copy - move() function corrupting files

The only way I could get my program to work is to wait 5 seconds after it detects a file. I tried really hard to just get it to move the oldest file with File::DirList

 @list = File::DirList::list('$directory','ia',1,1,1);

and stat, but I could never get the number out of the variables.

$last_modified = (stat($filename))[9]

My program works for me for now but who knows the kind of pressure people are going to put on it. Any hints on these in case I really do need to upload the oldest file?

My new code:

use CAM::PDF; use File::Copy; use File::stat; use Time::localtime; sleep(1); if ($o==0){ print "\nChecking for files...\n"; $o=1; } #Initialize title page pdf my $doc1 = CAM::PDF->new("$file1") || die "$CAM::PDF::errstr\n"; #Read each pdf file on the desktop opendir(DIR,$directory); my @files = grep{/\.pdf$/}readdir(DIR); if (@files){ print "Found file! Waiting 5 seconds before I move it.\n"; print "Name of file: $files[0]\n"; $o=0; sleep(5); } else{ continue; } closedir(DIR);

Replies are listed 'Best First'.
Re^3: File::Copy - move() function corrupting files
by Laurent_R (Canon) on Aug 25, 2014 at 17:29 UTC
    Well, do you have control on the process producing the files onto the desktop? Because the best solution is really to change this process so that it copies the files with a different name (say "*.pd_"), and that it renames them to "*.pdf" only when the file is complete. This way, when you grep the directory content, you only pick up files that are complete.

    Or create the files in a different directory on the same disk, and move it into the right directory once the file is complete.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1098532]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2018-06-23 18:23 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.