Skip to content

Instantly share code, notes, and snippets.

@Hotfirenet
Last active April 7, 2017 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hotfirenet/6f3fe8197289eeff3ffb42fee8067863 to your computer and use it in GitHub Desktop.
Save Hotfirenet/6f3fe8197289eeff3ffb42fee8067863 to your computer and use it in GitHub Desktop.
Permet de renommer tous les fichiers d'un repertoire
tell application "Finder"
set chemin to choose folder with prompt "Sélectionnez le dossier contenant les fichiers à renommer"
my inspecter(chemin) --appel routine avec transmission des variables
end tell
on inspecter(un_dossier)
-- récupération du nom du dossier
set ledossier to un_dossier as string
set ledossier to text 1 thru -2 of ledossier
set AppleScript's text item delimiters to {":"}
set ddd to get last text item of ledossier
tell application "Finder"
-- traitement des fichiers :
set les_fichiers to files of un_dossier
set lenumero to 1 --initialise le numero pour le dossier en cours
repeat with chaque_fichier in les_fichiers
-- traitement d'un fichier
set nom to name of chaque_fichier -- recupere 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 numerotation to lenumero as string --converti le numero en texte
set nouveaunom to (ddd & "_" & numerotation & "." & lextension) as string -- le nouveau nom dossier(DDD)+ _+extension
set name of file nom of un_dossier to nouveaunom --écrit le nom du fichier
set lenumero to lenumero + 1 --incremente la numérotation
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
# trouvé sur http://forum.macbidouille.com/index.php?showtopic=328354
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment