#!/usr/bin/perl -w use strict; my $dir = $ARGV[0]; # first command line argument opendir D, $dir or die "can't open $dir: $!\n"; # for each file in directory: my $file; while ($file = readdir(D)) { # only process files called "* screen res.jpg" next unless $file =~ /(.*) screen res.jpg/; # but only process them if the corresponding thumbnail exists and is +a file ($1 is the base name) next unless -f "$1 thumbnail.jpg"; # now do the family of renames. rename $file, "${1}sr.jpg" or die "can't rename \"$file\" as \"${1}sr.jpg\": $!\n"; rename "$1 thumbnail.jpg", "${1}tn.jpg" or die "can't rename \"$1 thumbnail.jpg\" as \"${1}tn.jpg\": $!\n"; rename "$1 8 by 10.tif", "${1}8b10.tif"; rename "$1 4 by 6.tif", "${1}4b6.tif"; # open the text file for write and close it again # to make a 0-length file open T, ">${1}.txt" or die "can't open text file ${1}.txt: $!\n"; close T; } closedir D;
update: hmm, "teach a man to fish" vs. "give a man a fish"?
Added comments for clarification.
In reply to Re: A monk in training with a problem
by bikeNomad
in thread A monk in training with a problem
by wiz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |