Hey there, I'm looking to move all files and folders from one directory to another, but I don't just want a full instant directory move. I'm looking to individually scan each file and folder from a parent directory and, keeping the sub-folder structure intact, only move them if they are older than 5 minutes of being modified to a new directory. So something like this:
$dir = '/current/directory/';
$newdir = '/new/directory/';
find(\&movefiles, $dir);
sub movefiles
{
$move_file = $File::Find::name;
$move_curDir = $File::Find::dir;
$move_curFile = $_;
$move_basedir = dirname($move_curDir);
$file_time = (stat($move_file))[9];
$current_time = time;
$time_dif = $current_time - $file_time;
if ($time_dif <= 300)
{
#Ignore
}
else
{
#Move
my $new_file = $move_file;
$new_file =~ s/old_folder/new_folder/;
copy("$move_file","$new_file") or die "Copy failed: $!";
After this, I'm looking to actually move the files and sub-folders of those files from the base current directory to the new current directory. Any thoughts? Thank you!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.