0

i need , some help , with my mini-script , to Fix , Spanish Filename with ISO_8859-1 and/or with part of names like "&#00243"

The Script its there : http://www.pastebin.com/vT5Z2BqE

Yesterday with a 3 Things , are working , i add more , and dont work anymore , i dont understand why .

Look , if i use that command in a "Bash Shell" / "Gnome-Terminal" like :

inukaze@Inukaze:~$ cd Filenames_to_fix inukaze@Inukaze:~/Filenames_to_fix$ inukaze@Inukaze:~/Filenames_to_fix$ expresion='&#00176' inukaze@Inukaze:~/Filenames_to_fix$ sustituto='°' inukaze@Inukaze:~/Filenames_to_fix$ ls *$expresion* 01 - La Espada del Augurio &#00176.avi inukaze@Inukaze:~/Filenames_to_fix$ for i in $( ls $expresion ); do > orig=$i > dest=$(echo $i | sed -e "s/$expresion/$sustituto/") > mv $orig $dest > done mv: no se puede efectuar stat' sobre «01»: No existe el fichero o el directorio mv: no se puede efectuarstat' sobre «-»: No existe el fichero o el directorio mv: no se puede efectuar stat' sobre «La»: No existe el fichero o el directorio mv: no se puede efectuarstat' sobre «Espada»: No existe el fichero o el directorio mv: no se puede efectuar stat' sobre «del»: No existe el fichero o el directorio mv: no se puede efectuarstat' sobre «Augurio»: No existe el fichero o el directorio mv: no se puede efectuar `stat' sobre «°»: No existe el fichero o el directorio 

I need , the change of part of filename "°" for "ª" , for example Someone / somebody , can explain why this error , and how to fix it ???

I dont wanna interactive mode , and dont wanna replace "extension" i wanna "rename" the bad part of filename , with the "Good" character in its place :D.

Thank you for readme , and sorry my bad english , thank you for any help can you give me with this script

3 Answers 3

1

You do not quote $orig and $dest and that causes problems when the filename contains spaces (mv is given the file name as several separate arguments (which is why it prints several error messages with parts of the file name)). Try to use

mv "$orig" "$dest" 

instead.

Sign up to request clarification or add additional context in comments.

1 Comment

Also the loop driver is wrong - you want for i in *$expresion*; do ...
0

The for loop uses whitespace as a delimiter. Since your file name contains whitespace, you will need to change what you are using as a delimiter.

Here is the equivalent using find and while

find . -maxdepth 1 -name "*${expresion}*" -print0 | while read -d $'\0' file do orig="$file" dest=$(echo "$file" | sed -e "s/${expresion}/${sustituto}/") mv "$orig" "$dest" done 

HOWEVER, a better solution is probably to use the rename command:

rename $expresion $sustituto *${expresion}* 

Comments

0

Is the rename command available?

rename $expresion $sustituto *$expresion* 

2 Comments

thank you for your suggestion . but i dont know if "rename" its available in all distro , like "mv"
The Mini-Script its Finished , i hope this works , for any linux user , with any Linux Distro . you can see all code in >> " pastebin.com/vT5Z2BqE " <<

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.