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

In reply to Re: Moving files recursively to new subfolder by Anonymous Monk
in thread Moving files recursively to new subfolder by jayu_rao

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.