[Tutor] renaming files within a directory

Tim Golden mail at timgolden.me.uk
Sun Jul 26 17:13:38 CEST 2009


davidwilson at Safe-mail.net wrote:
> Hello,
> I have a directory containing svg/Flag_of_United_States.svg etc...
> 
> 
> Flag_of_the_Seychelles.svg
> Flag_of_the_Solomon_Islands.svg
> Flag_of_the_United_Arab_Emirates.svg
> Flag_of_the_United_Kingdom.svg
> Flag_of_the_United_States.svg
> Flag_of_the_Vatican_City.svg
> 
> 
> Also I have a CSV file like
> 
> "us", "United States"
> "es", "Spain"
> 
> ....
> 
> How can I rename the svg files so that they become:
> 
> flag-us.svg
> flag-es.svg


This is one of those ones where it helps if you have
a go first and tell us how far you got, or where
the problem lies. Otherwise you're likely to get
a lot of sarcastically helpful replies along the lines
of:

move Flag_of_the_Seychelles.svg flag-sc.svg


To get you started if you're nowhere at the moment,
you want to create a dictionary from your csv which maps 
the long name to the short name so that can then
parse the file name to find the long name, use the
dictionary to find the short name, and then issue
a rename command to the new name.

TJG


More information about the Tutor mailing list