Max79 has asked for the wisdom of the Perl Monks concerning the following question:
GridSquare_0000000077_FoilHole_0000000001_Data_0000000002_20120315_103721.jpg GridSquare_0000000077_FoilHole_0000000001_Data_0000000002_20120315_103721.xml
The number of this files are not sequential I would like to rename this file in a more handy way as 1.jpg and 1.xml, 2.jpg 2.xml up to the last one. In the position number 498 and 500 of the file *xml there are two numbers. I would like also to create a directory with this two numbers (something as 15 or 20) and move in this directory the corresponding files. So if th20120315_103721.xml has in position 498 and 500 the numbers 1 and 5 I would like to move this file and corresponding jpeg in the dir 15 and so on. I started step by step. First with a script that should have modified the name but indeed remove the files !
Thank you in advance Max< #!/usr/bin/perl -w ## ## use strict ; my $dir = 'ParticleAcquisitionDataImages/'; my @fileList = glob "${dir}*jmg*"; foreach (@fileList) { next if -d; my $oldname = $_; # $_=substr($_, 0, 1, ''); # s/.//; s/^.(.*).$/$1/; rename $oldname, $_ or $_ = $oldname, warn $_, ' not renamed: ', $!; } close >
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Renaming files in a directory in sequence
by Anonymous Monk on Mar 28, 2012 at 21:16 UTC | |
Re: Renaming files in a directory in sequence
by graff (Chancellor) on Mar 29, 2012 at 05:47 UTC | |
Re: Renaming files in a directory in sequence
by thundergnat (Deacon) on Mar 28, 2012 at 14:15 UTC | |
by Anonymous Monk on Mar 29, 2012 at 14:24 UTC |