Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: move files to directories based on criteria

by metaperl (Curate)
on Jul 10, 2009 at 19:25 UTC ( #779016=note: print w/replies, xml ) Need Help??


in reply to move files to directories based on criteria

Here's a version that moves files to a multi-level destination of YYYY/MM/DD/HH
#!/usr/bin/perl use strict; use warnings; use lib '../..' ; use File::Copy; use File::Find; use File::Path; use File::Stat; my $root_dir = find_root_dir(); our $prefix; sub wanted { my ($file)=$_; return if -d $file; return if $File::Find::dir ne $root_dir; my $dir_to_make = categorize($file); File::Path::make_path($dir_to_make); File::Copy::move($file, $dir_to_make); } sub find_root_dir { use Local::Config; Local::Config->new->logdir; } sub categorize { my($file)=@_; my $stat = File::Stat->new($file); #substr($file, 0, 5); use DateTime; my $dt = DateTime->from_epoch( epoch => $stat->mtime, time_zone => 'EST' ); my $path = $dt->ymd('/'); $path .= "/" . $dt->hour; $path; } File::Find::find(\&wanted, $root_dir); # thanks to jhannah in #perl-help

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://779016]
help
Chatterbox?
[shmem]: karlgoethebier: es ist theologisch umstritten, ob jesus an christi himmelfahrt tatsächlich besoffen und mit bollerwagen zu seinem vater aufgebrochen ist
[karlgoethebier]: shmem: Ja ischweis
[karlgoethebier]: shmem: Vielleicht hat er in den Bollerwagen gebrochen?
[karlgoethebier]: shmem:Ach so. Bollerwagen ist eigentlich was für Kinder. Bei uns fahren sie mit Traktoren und Feuerwehrwagen rum...
[shmem]: karlgoethebier: here abouts people are sitting in big tents, gulp beer and ingest badly scorched chicken and sausages while (not) listening to afwul musik

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (13)
As of 2017-05-25 12:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?