in reply to File Name Pattern

"how do I do the the match to see if the file is 3 or 4 or 5 or 6 digits long and how would I add the characters to the front of the files and get those first 3 digits??"

use printf or sprintf:

printf("%06d\n",$_) for (123, 1234, 12345, 123456); my $val = sprintf("%06d",123);
To get the first three digits:
my $name = '012345'; my ($three) = $name =~ /^(\d\d\d)/;
You might want to look at File::MMagic if you have to ensure that the files really are jpg's.

UPDATE:
more code for you :)

use strict; while (<DATA>) { chomp; my ($numbs) = $_ =~ /^(\d+)/; my $formatted = sprintf("%06d",$numbs) . '.jpg'; my ($dir) = $formatted =~ /^(\d\d\d)/; print "filename: $formatted\t\tdirname: $dir\n"; } __DATA__ 123.jpg 1234.jpg 12345.jpg 123456.jpg

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re: (jeffa) Re: File Name Pattern
by FamousLongAgo (Friar) on Dec 13, 2002 at 16:52 UTC
    You might also want to make sure that all the filenames are in the format you think they are:
    warn "Invalid file $file" unless $file =~ /^\d{3,6}\.jpe?g$/; This will complain unless the filename consists of 3-6 digits, followed by a period and the suffix "jpg" or "jpeg". You might want to make a pass before you start moving files, just to make sure your directories contain what you think they contain.