Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Moving files recursively to new subfolder

by Anonymous Monk
on May 28, 2015 at 23:15 UTC ( [id://1128205]=note: print w/replies, xml ) Need Help??


in reply to Moving files recursively to new subfolder

You're doing a lot of shell programming... the problem is with your system call, shells can be very different accross systems (their syntax can vary), as can ls/cp/mv... and their options

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
    Thanks much for your reply. Unfortunately I do not have control over the machine and hence I can not install the File::Find::Rule.pm on the machines where I need to run the perl script. Any other suggestions?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-24 00:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found