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 >
In reply to Renaming files in a directory in sequence by Max79
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |