Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Watching Creation File and send it to Server

by suaveant (Parson)
on Nov 06, 2001 at 20:13 UTC ( [id://123604]=note: print w/replies, xml ) Need Help??


in reply to Watching Creation File and send it to Server

Aside from renaming or moving it when the upload is finished to specify such, your best option is to keep an eye on the file (programmatically). Either watch the modified time or the file size. When it hasn't changed in a minute or so, the file is probably done. Something like this...
my %files = ('foo.txt' => [0,time()], 'bar.csv' => [0,time()]); while(%files) { for(keys %files) { if((-s $_ == $files{$_}[0]) && (time()-$files{$_}[1]>60)) { &move_file($_); delete $files{$_}; } else { $files{$_} = [(-s $_),time()]; } sleep 1; } }
this is not tested, and could be optimized, but what it does is have a hash of files (which you could add to as you go along). The values of the hash is an array holding file size and time it last changed. The code checks to see if the size has changed, and if the time it hasn't changed is over 60 seconds... You have to leave some amount of time since data tends to be written in chunks.

If windows changes the modified time as the file gets written a simple

if(time() - (stat $file)[9] > 60)
would be a sufficient test to see if $file has changed in the last 60 seconds...

                - Ant
                - Some of my best work - (1 2 3)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-20 01:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found