Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use CGI qw(:standard); use strict; use File::Find; use vars qw($_amountOfFiles); my $_excludeList = 1; my $_expcludeMain = 1; my $dir = "/home/path/public_html/files"; my %_excludeListing = ( 'cgi-bin' => "cgi-bin", ); #my $dir = shift || die "usage $0 <dir>\n"; print "Content-type: text/plain\n\n"; $_amountOfFiles = 0; finddepth(\&do_this, $dir); print "Renamed: $_amountOfFiles files\nDone\n"; #rmdir $dir; sub do_this { # ignore . and .. return if /^\.\.?$/; if (-d) { if($_excludeList && exists($_excludeListing{$_})) { print "Skipping dir: $File::Find::name\n"; return; } if($_expcludeMain && $_ eq "$dir") { print "Skipping dir: $File::Find::name\n"; return; } # print "Removing dir: $File::Find::name\n"; # rmdir; } else { print "."; $_amountOfFiles++; unlink; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Renaming Every File in a directory
by Athanasius (Archbishop) on Apr 28, 2015 at 03:47 UTC | |
by Anonymous Monk on Apr 28, 2015 at 04:14 UTC | |
by Athanasius (Archbishop) on Apr 28, 2015 at 04:40 UTC | |
|
Re: Renaming Every File in a directory
by Don Coyote (Hermit) on Apr 28, 2015 at 06:44 UTC | |
|
Re: Renaming Every File in a directory
by Marshall (Canon) on Apr 28, 2015 at 05:09 UTC |