in reply to Rename old files that do not begin with a dot

Found a third bug. $_ isn't the variable you should be using. $_ is relative to some path relative under /Users/admin/Documents/ScriptTest/, but you're trying to rename a file in the current directory.

my $limit = 20; find (\&CheckFile, "/Users/admin/Documents/ScriptTest/"); sub CheckFile { my $age = -M $File::Find::name; if ( -f $File::Find::name && !/^\./ && $age > $limit ) { rename ( "$File::Find::dir/$_", "$File::Find::dir/.$_") or die "rename failed: $!"; } else { print $File::Find::name; print " is a youthfull ", int($age)," days old\n"; } }

Replies are listed 'Best First'.
Re^2: Rename old files that do not begin with a dot
by Anonymous Monk on Oct 27, 2008 at 22:31 UTC
    Thank you so much for your help and advice,
    kind regards
    Mark