Given the following file/directory structure:
/photos/1/original/filename1.jpg /photos/1/thumb/filename1.jpg /photos/2/original/filename2.jpg /photos/2/thumb/filename2.jpg /photos/3/original/filename3.jpg /photos/3/thumb/filename3.jpg
…etc. I’m looking for the regexp to convert the file/directory structure to:
/photos/1/original.jpg /photos/1/thumb.jpg /photos/2/original.jpg /photos/2/thumb.jpg /photos/3/original.jpg /photos/3/thumb.jpg
…etc. I’ve got scripts to do the file renaming in ruby or perl…just missing the proper regexp.
Perl solution
As requested, to match any keyword, not just ‘original’ or ‘thumb’, assuming that the /photos/nn remains the same:
Adapting this solution to also remove the directories if they are empty
I’m not sure what this will do if the directory is not empty when you go to unlink it.