|
Page 1 of 3 I have often the need to rename many files in order to remove the specials characters in the file name. Many applications will dislike such characters, and I want to get rid of them. Of course, I don't want to rename all these files by hand, I wrote a script that will replace any special character with some replacement character.
For instance, suppose that you have the following file:
01 I don't like these specials é,à characters.mp3
If you have only one file, that's ok, but if you have tens of mp3 files to rename the task would be tedious.
Typically, you want to replace the "é", "à", ",", "'", the space or any character that you may encounter. There is command available to help you: rename. Unfortunately, this will replace only the first occurrence of the string you want to replace. You would need to run it as long as you have spaces in your file name for example.
The following script will exactly do the trick. It will take the file name as input, create a string with this file name, and use the sed editor to replace the unwanted characters. It will replace all occurrences of all the strings you want to replace. You will define an array containing all of the characters you want to replace, and an array containing all the replacement characters. You also have the option to replace all the unwanted characters with a single replacement character.
|