-- Renomme tous les fichiers d'un dossier y compris dans les sous dossiers
-- Avec majuscule en debut de mot laisse mot en majuscule si existe
tell application "Finder"
set chemin to choose folder with prompt "Sélectionnez le dossier contenant les fichiers à renommer"
my inspecter(chemin)
end tell
on inspecter(un_dossier)
tell application "Finder"
-- traitement des fichiers :
set les_fichiers to files of un_dossier
repeat with chaque_fichier in les_fichiers
-- traitement d'un fichier
tell application "Finder"
set nom to name of chaque_fichier --récupère le nom du fichier
set extens to document file nom in un_dossier --recupere l extension du fichier
set lextension to name extension of extens
set texte to nom
set leNbchar to count of every character of texte
set lePremier to 0
set ledebut to 0
set lesChar to {" ", "(", ".", "_", "-"} -- liste des caractères aprés lesquels on met une majuscule
repeat with i from 1 to leNbchar
set leChar to text from i to i of texte
log leChar
set lePremier to lePremier + 1
set ledebut to ledebut + 1
if leChar is in lesChar then
set lePremier to 0
end if
if lePremier = 1 then
set leChar to text from i to i of texte
set leNum to ASCII number of leChar
if leNum > 96 and leNum < 123 then
set leNum to leNum - 32
set NewChar to (ASCII character leNum)
set x to i - 1
if x = 0 then set x to 1
set LeMotdebut to text 1 thru x of texte
set LeMotFin to text from (i + 1) to leNbchar of texte
if ledebut = 1 then
set texte to NewChar & LeMotFin
else
set texte to LeMotdebut & NewChar & LeMotFin
end if
end if
end if
end repeat
set nouveaunom to texte & "." & lextension as string -- le nouveau nom
set name of file nom of un_dossier to nouveaunom
end tell
end repeat
-- traitement des dossiers :
set les_dossiers to folders of un_dossier
repeat with chaque_dossier in les_dossiers
-- traitement d'un dossier
my inspecter(chaque_dossier)
end repeat
end tell
end inspecter
tell application "Finder"
(display dialog ("waouou ... Ca y est c'est fait !") buttons {"Salut !"})
end tell