in reply to Moving files recursively to new subfolder
If you were to use File::Find::Rule with Path::Tiny your program gets a little simpler and more portable , like this, using the other AMs renaming idea
#!/usr/bin/perl -- use strict; use warnings; use POSIX(); use File::Find::Rule qw/ find rule /; use Path::Tiny qw/ path /; my $dir_to_search = 'goner'; print join ' ', "Before move: ", find( file => in => $dir_to_search ,) +, "\n"; my_move_log_files($dir_to_search); print join ' ', "After move: ", find( file => in => $dir_to_search ,) +, "\n"; exit( 0 ); sub my_move_log_files { my @log_dirs_to_move = @_; for my $src_dir (@log_dirs_to_move) { my $dated = "logs_dir".POSIX::strftime('%Y%m%d%H%M%S', localt +ime ); my $final = path( $src_dir, $dated); my $temp = path( $src_dir, '..', $dated); path( $src_dir )->move( $temp ); path( $src_dir )->mkpath; path( $temp )->move( $final ); } } __END__ $ perl file-find-rule-path-tiny-move-rename-goner-assubdir.pl Before move: goner/touchme.txt After move: goner/logs_dir20150528161733/touchme.txt
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Moving files recursively to new subfolder
by jayu_rao (Sexton) on May 29, 2015 at 04:04 UTC | |
by Anonymous Monk on May 29, 2015 at 05:51 UTC |