Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: copy or ftp file by file timestamp

by imrags (Monk)
on Jul 23, 2009 at 04:49 UTC ( #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.

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://782556]
[atcroft]: .oO(Then there is the effect if a site changes their timezone, such as when the International Date Line was moved by the purchase of Alaska by the US from Russia in 1867, or several places (I cannot recall off-hand) that moved from one side of the Date
[atcroft]: Line to the other recently....)
[atcroft]: .oO(Then again, you also have to be careful if you had it to the database, and be aware of any assumptions it makes (such as SQLite assuming Gregorian calendar and a day of exactly 86400 seconds)...)

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2017-04-29 04:53 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (531 votes). Check out past polls.