I have this code to delete every file in a directory and skip directories... but I'm not remembering how to use the sub to rename files...
#!/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;
}
}
Where unlink is, what do I put to rename the file, IF it ends in .jpg to a Random string.jpg?
Instead of unlink?
I have not been writing Perl programming for a few years, and I feel like I'm getting dementia... I am at a total loss on it.
Can you point me in the right direction?
Please.
Rich
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.