Posted: 5/5/2008 4:22:36 PM EDT
|
Wrote this little diddy today. Proves useful to me else I wouldn't of wrote it. Just for fun tell me what it does and later I'll explain why I wrote it opendir (DIR, '.') or die "Couldn't open directory, $!"; while ($file1 = readdir DIR) { if ($file1 =~/\.JPG|\.jpg/ ) { $file2 = $file1; #test_file (0).JPG $file2 =~ s/\.JPG/\.jpg/; $file2 =~ s/\(0\)/\(00\)/; $file2 =~ s/\(1\)/\(01\)/; $file2 =~ s/\(2\)/\(02\)/; $file2 =~ s/\(3\)/\(03\)/; $file2 =~ s/\(4\)/\(04\)/; $file2 =~ s/\(5\)/\(05\)/; $file2 =~ s/\(6\)/\(06\)/; $file2 =~ s/\(7\)/\(07\)/; $file2 =~ s/\(8\)/\(08\)/; $file2 =~ s/\(9\)/\(09\)/; $file2 =~ s/[ ()]//g; print "renaming $file1 to $file2\n"; rename($file1, $file2); } } closedir DIR; exit 0; |
|
It just tidies up the file names, getting rid of blanks and the brackets and making all the numbers 2 digits. If you have a bunch of files in Windows, and highlight them in Explorer and right mouse click -> rename , they'll be renamed with blanks and parenthesis around the file number. When you upload these to photobucket, photobucket mangles the name a bit, so I decided to just turn them into a filename photobucket won't alter. # Before: # # Directory of D:\temp3 # # 05/05/2008 01:42 PM <DIR> . # 05/05/2008 01:42 PM <DIR> .. # 05/05/2008 12:44 PM <DIR> backup # 05/05/2008 01:45 PM 989 renamejpg.pl # 05/05/2008 12:34 PM 8,122 test_file (0).jpg # 05/05/2008 12:34 PM 8,122 test_file (1).jpg # 05/05/2008 12:34 PM 8,122 test_file (10).jpg # 05/05/2008 12:34 PM 8,122 test_file (11).jpg # 05/05/2008 12:34 PM 8,122 test_file (12).jpg # 05/05/2008 12:34 PM 8,122 test_file (13).jpg # 05/05/2008 12:34 PM 8,122 test_file (2).jpg # 05/05/2008 12:34 PM 8,122 test_file (3).jpg # 05/05/2008 12:34 PM 8,122 test_file (4).jpg # 05/05/2008 12:34 PM 8,122 test_file (5).jpg # 05/05/2008 12:34 PM 8,122 test_file (6).jpg # 05/05/2008 12:34 PM 8,122 test_file (7).jpg # 05/05/2008 12:34 PM 8,122 test_file (8).jpg # 05/05/2008 12:34 PM 8,122 test_file (9).jpg # # After: # # Directory of D:\temp3 # # 05/05/2008 01:48 PM <DIR> . # 05/05/2008 01:48 PM <DIR> .. # 05/05/2008 12:44 PM <DIR> backup # 05/05/2008 01:48 PM 2,133 renamejpg.pl # 05/05/2008 12:34 PM 8,122 test_file00.jpg # 05/05/2008 12:34 PM 8,122 test_file01.jpg # 05/05/2008 12:34 PM 8,122 test_file02.jpg # 05/05/2008 12:34 PM 8,122 test_file03.jpg # 05/05/2008 12:34 PM 8,122 test_file04.jpg # 05/05/2008 12:34 PM 8,122 test_file05.jpg # 05/05/2008 12:34 PM 8,122 test_file06.jpg # 05/05/2008 12:34 PM 8,122 test_file07.jpg # 05/05/2008 12:34 PM 8,122 test_file08.jpg # 05/05/2008 12:34 PM 8,122 test_file09.jpg # 05/05/2008 12:34 PM 8,122 test_file10.jpg # 05/05/2008 12:34 PM 8,122 test_file11.jpg # 05/05/2008 12:34 PM 8,122 test_file12.jpg # 05/05/2008 12:34 PM 8,122 test_file13.jpg |