Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: copy or ftp file by file timestamp

by imrags (Monk)
on Jul 23, 2009 at 04:49 UTC ( [id://782556]=note: print w/replies, xml ) Need Help??


in reply to copy or ftp file by file timestamp

Try something like this:
scalar localtime((stat("$dir_name/$file"))[9]);
This will give the modified/created time of the file. If you are failing to browse thru the directory, then here's the code.
print_dir ( "YOUR/DIRECTORY/PATH" ); sub print_dir { my ($dir_name) = @_; opendir ( my $dir_h , "$dir_name") or die "Unable to open dir :$dir +_name: $!\n"; while ( my $file = readdir($dir_h) ) { next if ( "$dir_name/$file" =~ /\/\.$/ or "$dir_name/$file" =~ /\ +/\.\.$/ ); if ( -d "$dir_name/$file" ) { print_dir ( "$dir_name/$file" ); } print "$dir_name/$file - "."\n"; } }
It'll browse thru directories/sub-directories as well.
Raghu

Replies are listed 'Best First'.
Re^2: copy or ftp file by file timestamp
by breezykatt (Acolyte) on Jul 23, 2009 at 18:13 UTC
    Thank you for the response. I have not tried it out yet, but looks much tighter than what I wrote. I was able to get the timestamp of the files, the problem I am experiencing is how to copy a set of files to another directory, say every 300 seconds. So, for example, if you take the current time and read in the files in a particular directory, whatever files are in that 5 minute range should be copied over. The script needs to run for 24 hours straight until all files are copied or moved over. The next part is even more difficult. I need to make it modular enough to consider multiple directories. So for example, one directory might copy files over every 300 seconds while another directory might copy files over every 1800 seconds. Hope that makes sense? I do not know if I should make 1 perl script for each directory or make like 25 different perl scripts running at different intervals per directory. I'm having difficulty writing one script to do all.
      I might not be explaining this well....Basically - directory1 has 3,000 files in it with timestamps all throughout one day (July 23, 2009). directory2 has 5,000 files in it with timestamps all throughout one day (July 23, 2009). directory 1 should copy files over at a predefined interval rate, say 300 seconds. so if I can take a current start time say 9:00 am, and copy all files at 9:05 am that range from 9:00 am - 9:05 am. sleep for 300 seconds, then at 9:10 copy all files from 9:05 - 9:10, etc.... directory 2 follows the same methodology but runs at 1800 second intervals. the problem i am having is writing 1 perl script, not a bunch to do this. it doesn't have to be perfect, but just needs to do something along those lines.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-03-28 14:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found