Forums
Nouveaux sujets
Chercher dans les forums
Quoi de neuf ?
Nouveaux sujets
Nouveaux messages de profil
Activité récente
MacGeneration
MacGeneration
iGeneration
WatchGeneration
Je veux le.top
iOccasion
RefurbGeneration
Connexion
S'inscrire
Rechercher
Rechercher par titre uniquement
Par:
Rechercher par titre uniquement
Par:
Rechercher
Rechercher par titre uniquement
Par:
Rechercher par titre uniquement
Par:
Menu
Install the app
Install
Forums
Développement
Raccourcis et automatisation
Renommer fichiers en masse puis les déplacer dans un dossier parent
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Vous utilisez un navigateur non à jour ou ancien. Il ne peut pas afficher ce site ou d'autres sites correctement.
Vous devez le mettre à jour ou utiliser un
navigateur alternatif
.
Répondre à la discussion
Message
<blockquote data-quote="zeltron54" data-source="post: 14177113" data-attributes="member: 101652"><p>Bonsoir,</p><p></p><p>J'avais voulu trop bien faire en renommant les fichiers et les dossiers... Mais une erreur se produit lors du renommage des dossiers.</p><p>Il faudra que je cherche pour résoudre ce Bug.</p><p>En attendant je te mets le script qui ne renomme que les fichiers...</p><p></p><p>[CODE]-- renomme les fichiers en supprimant les caractères spéciaux</p><p>--ÀÁÂàÄÅàáâàäåÒÓÔÕÖòóôõöÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ()[]{}/%@#",;?!.\>< (majuscule par minuscule)</p><p>--AAAaAAaaaaaaOOOOOoooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn---------------__--</p><p>tell application "Finder"</p><p> set lechemin to choose folder with prompt "Sélectionnez le dossier contenant les fichiers et dossiers à traiter"</p><p> my inspecter(lechemin)</p><p>end tell</p><p></p><p>tell application "Finder"</p><p> my inspecter(lechemin)</p><p>end tell</p><p></p><p>on inspecter(lechemin)</p><p> tell application "Finder"</p><p> -- traitement des fichiers :</p><p> set les_fichiers to files of lechemin</p><p> repeat with chaque_fichier in les_fichiers</p><p> -- traitement d'un fichier</p><p> tell application "Finder"</p><p> try</p><p> set lefichier to chaque_fichier</p><p> set AppleScript's text item delimiters to {""}</p><p> set nom to name of chaque_fichier --récupère le nom du fichier</p><p> set extens to file nom in lechemin --recupere l extension du fichier</p><p> set lextension to name extension of extens</p><p> if lextension is not "" then</p><p> set sauv to AppleScript's text item delimiters --sauvegarder la variable delimiteur</p><p> set AppleScript's text item delimiters to {"."} --récupère la partie avant le dernier "."</p><p> set elements to text items of nom</p><p> set nomcourt to (items 1 thru -2 of elements) as string</p><p> set AppleScript's text item delimiters to sauv --restaurer la variable delimiteur</p><p> else</p><p> set nomcourt to nom</p><p> end if</p><p> on error</p><p> set lelog to open for access ((path to desktop folder as text) & "les erreurs.txt") as text with write permission</p><p> write "Le nom du fichier n'a pas pu être extrait : " & lefichier & return to lelog starting at eof</p><p> close access lelog</p><p> end try</p><p> set pourerreur to lefichier as string</p><p> set nouveaunom to my remplace(nomcourt, pourerreur)</p><p> </p><p> if nomcourt is not nouveaunom then</p><p> try</p><p> set a to container of lefichier as string</p><p> set verifexist to a & nouveaunom & "." & lextension</p><p> if exists verifexist then</p><p> set nouveaunom to nouveaunom & "2"</p><p> end if</p><p> if lextension = "" then</p><p> set name of lefichier to nouveaunom</p><p> else</p><p> set name of lefichier to nouveaunom & "." & lextension -- renomme le fichier</p><p> end if</p><p> -- Ecrit un fichier erreur sur le bureau si erreur</p><p> on error</p><p> set lelog to open for access ((path to desktop folder as text) & "les erreurs.txt") as text with write permission</p><p> write "Le fichier n'a pas pu être renommer : " & pourerreur & return to lelog starting at eof</p><p> close access lelog</p><p> end try</p><p> end if</p><p> </p><p> end tell</p><p> end repeat</p><p> </p><p> </p><p> -- traitement des dossiers :</p><p> set les_dossiers to folders of lechemin</p><p> repeat with chaque_dossier in les_dossiers</p><p> -- traitement d'un dossier</p><p> my inspecter(chaque_dossier)</p><p> end repeat</p><p> end tell</p><p>end inspecter</p><p></p><p>tell application "Finder"</p><p> activate</p><p> (display dialog ("waouou ... Ca y est c'est fait !") buttons {"Salut !"})</p><p>end tell</p><p></p><p>on remplace(mavar, pourerreur)</p><p> set aremplacer to {203, 231, 229, 136, 128, 129, 136, 135, 137, 136, 138, 140, 241, 238, 239, 205, 133, 152, 151, 153, 155, 154, 233, 131, 230, 232, 143, 142, 144, 145, 130, 141, 237, 234, 235, 236, 147, 146, 148, 149, 244, 242, 243, 134, 157, 156, 158, 159, 216, 132, 150, 40, 41, 91, 93, 123, 125, 47, 37, 64, 35, 34, 44, 59, 63, 33, 46, 92, 62, 60, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90}</p><p> set par to {97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 101, 101, 101, 101, 101, 101, 101, 101, 99, 99, 105, 105, 105, 105, 105, 105, 105, 105, 117, 117, 117, 117, 117, 117, 117, 117, 121, 110, 110, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 95, 95, 45, 45, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122}</p><p> set nbar to count aremplacer</p><p> set new to mavar</p><p> </p><p> set lesblancs to count character in new</p><p> repeat --supprime espace fin</p><p> if character lesblancs of new is not " " then</p><p> exit repeat</p><p> end if</p><p> set new to text 1 thru (lesblancs - 1) of new</p><p> set lesblancs to count characters in new</p><p> end repeat</p><p> repeat --supprime espace debut</p><p> if character 1 of new is not " " then</p><p> exit repeat</p><p> end if</p><p> set new to text 2 thru lesblancs of new</p><p> set lesblancs to count characters in new</p><p> end repeat</p><p> -- remplace les espaces par des tirets</p><p> set nb to count characters in new</p><p> repeat with i from 1 to nb</p><p> if character i of new is " " then</p><p> set new to text 1 thru (i - 1) of new & "-" & text (i + 1) thru nb of new</p><p> end if</p><p> end repeat</p><p> set nb to count characters in new</p><p> set i to 1</p><p> --supprime les tirets qui se suivent</p><p> repeat</p><p> if character i of new is "-" then</p><p> if character (i + 1) of new is "-" then</p><p> if i = 1 then</p><p> set new to text 2 thru nb of new</p><p> set nb to nb - 1</p><p> set i to i - 1</p><p> else</p><p> set new to text 1 thru (i - 1) of new & text (i + 1) thru nb of new</p><p> set nb to nb - 1</p><p> set i to i - 1</p><p> end if</p><p> end if</p><p> end if</p><p> set i to i + 1</p><p> if i = nb then exit repeat</p><p> end repeat</p><p> -- remplace les caractères de la liste</p><p> set nb to count characters in new</p><p> set mavar to new</p><p> try</p><p> repeat with i from 1 to nb</p><p> set a to character i in mavar</p><p> set lavaleur to ASCII number a</p><p> repeat with j from 1 to nbar</p><p> if item j of aremplacer is lavaleur then</p><p> if lavaleur = 60 or lavaleur = 62 then --traite le ><</p><p> if i = 1 then</p><p> set new to (text 2 thru nb of mavar)</p><p> set avant to ""</p><p> else</p><p> set avant to text 1 thru (i - 1) of new</p><p> end if</p><p> if i = nb then</p><p> set new to avant</p><p> else</p><p> set new to avant & text nb thru -(nb - i) of mavar</p><p> end if</p><p> </p><p> else --traite les autres caracteres</p><p> set newcar to ASCII character (item j of par)</p><p> if i = 1 then</p><p> set new to newcar & (text 2 thru nb of new)</p><p> set avant to ""</p><p> else</p><p> set avant to text 1 thru (i - 1) of new</p><p> end if</p><p> if i = nb then</p><p> set new to avant & newcar</p><p> else</p><p> set new to avant & newcar & text nb thru -(nb - i) of mavar</p><p> end if</p><p> end if</p><p> end if</p><p> end repeat</p><p> end repeat</p><p> on error</p><p> -- Ecrit un fichier erreur sur le bureau si erreur</p><p> set lelog to open for access ((path to desktop folder as text) & "les erreurs.txt") as text with write permission</p><p> write "Le caractère n'a pas pu être remplacer : " & pourerreur & return to lelog starting at eof</p><p> close access lelog</p><p> end try</p><p> set mavar to new</p><p>end remplace[/CODE]</p></blockquote><p></p>
[QUOTE="zeltron54, post: 14177113, member: 101652"] Bonsoir, J'avais voulu trop bien faire en renommant les fichiers et les dossiers... Mais une erreur se produit lors du renommage des dossiers. Il faudra que je cherche pour résoudre ce Bug. En attendant je te mets le script qui ne renomme que les fichiers... [CODE]-- renomme les fichiers en supprimant les caractères spéciaux --ÀÁÂàÄÅàáâàäåÒÓÔÕÖòóôõöÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ()[]{}/%@#",;?!.\>< (majuscule par minuscule) --AAAaAAaaaaaaOOOOOoooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn---------------__-- tell application "Finder" set lechemin to choose folder with prompt "Sélectionnez le dossier contenant les fichiers et dossiers à traiter" my inspecter(lechemin) end tell tell application "Finder" my inspecter(lechemin) end tell on inspecter(lechemin) tell application "Finder" -- traitement des fichiers : set les_fichiers to files of lechemin repeat with chaque_fichier in les_fichiers -- traitement d'un fichier tell application "Finder" try set lefichier to chaque_fichier set AppleScript's text item delimiters to {""} set nom to name of chaque_fichier --récupère le nom du fichier set extens to file nom in lechemin --recupere l extension du fichier set lextension to name extension of extens if lextension is not "" then set sauv to AppleScript's text item delimiters --sauvegarder la variable delimiteur set AppleScript's text item delimiters to {"."} --récupère la partie avant le dernier "." set elements to text items of nom set nomcourt to (items 1 thru -2 of elements) as string set AppleScript's text item delimiters to sauv --restaurer la variable delimiteur else set nomcourt to nom end if on error set lelog to open for access ((path to desktop folder as text) & "les erreurs.txt") as text with write permission write "Le nom du fichier n'a pas pu être extrait : " & lefichier & return to lelog starting at eof close access lelog end try set pourerreur to lefichier as string set nouveaunom to my remplace(nomcourt, pourerreur) if nomcourt is not nouveaunom then try set a to container of lefichier as string set verifexist to a & nouveaunom & "." & lextension if exists verifexist then set nouveaunom to nouveaunom & "2" end if if lextension = "" then set name of lefichier to nouveaunom else set name of lefichier to nouveaunom & "." & lextension -- renomme le fichier end if -- Ecrit un fichier erreur sur le bureau si erreur on error set lelog to open for access ((path to desktop folder as text) & "les erreurs.txt") as text with write permission write "Le fichier n'a pas pu être renommer : " & pourerreur & return to lelog starting at eof close access lelog end try end if end tell end repeat -- traitement des dossiers : set les_dossiers to folders of lechemin repeat with chaque_dossier in les_dossiers -- traitement d'un dossier my inspecter(chaque_dossier) end repeat end tell end inspecter tell application "Finder" activate (display dialog ("waouou ... Ca y est c'est fait !") buttons {"Salut !"}) end tell on remplace(mavar, pourerreur) set aremplacer to {203, 231, 229, 136, 128, 129, 136, 135, 137, 136, 138, 140, 241, 238, 239, 205, 133, 152, 151, 153, 155, 154, 233, 131, 230, 232, 143, 142, 144, 145, 130, 141, 237, 234, 235, 236, 147, 146, 148, 149, 244, 242, 243, 134, 157, 156, 158, 159, 216, 132, 150, 40, 41, 91, 93, 123, 125, 47, 37, 64, 35, 34, 44, 59, 63, 33, 46, 92, 62, 60, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90} set par to {97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 97, 111, 111, 111, 111, 111, 111, 111, 111, 111, 111, 101, 101, 101, 101, 101, 101, 101, 101, 99, 99, 105, 105, 105, 105, 105, 105, 105, 105, 117, 117, 117, 117, 117, 117, 117, 117, 121, 110, 110, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 95, 95, 45, 45, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122} set nbar to count aremplacer set new to mavar set lesblancs to count character in new repeat --supprime espace fin if character lesblancs of new is not " " then exit repeat end if set new to text 1 thru (lesblancs - 1) of new set lesblancs to count characters in new end repeat repeat --supprime espace debut if character 1 of new is not " " then exit repeat end if set new to text 2 thru lesblancs of new set lesblancs to count characters in new end repeat -- remplace les espaces par des tirets set nb to count characters in new repeat with i from 1 to nb if character i of new is " " then set new to text 1 thru (i - 1) of new & "-" & text (i + 1) thru nb of new end if end repeat set nb to count characters in new set i to 1 --supprime les tirets qui se suivent repeat if character i of new is "-" then if character (i + 1) of new is "-" then if i = 1 then set new to text 2 thru nb of new set nb to nb - 1 set i to i - 1 else set new to text 1 thru (i - 1) of new & text (i + 1) thru nb of new set nb to nb - 1 set i to i - 1 end if end if end if set i to i + 1 if i = nb then exit repeat end repeat -- remplace les caractères de la liste set nb to count characters in new set mavar to new try repeat with i from 1 to nb set a to character i in mavar set lavaleur to ASCII number a repeat with j from 1 to nbar if item j of aremplacer is lavaleur then if lavaleur = 60 or lavaleur = 62 then --traite le >< if i = 1 then set new to (text 2 thru nb of mavar) set avant to "" else set avant to text 1 thru (i - 1) of new end if if i = nb then set new to avant else set new to avant & text nb thru -(nb - i) of mavar end if else --traite les autres caracteres set newcar to ASCII character (item j of par) if i = 1 then set new to newcar & (text 2 thru nb of new) set avant to "" else set avant to text 1 thru (i - 1) of new end if if i = nb then set new to avant & newcar else set new to avant & newcar & text nb thru -(nb - i) of mavar end if end if end if end repeat end repeat on error -- Ecrit un fichier erreur sur le bureau si erreur set lelog to open for access ((path to desktop folder as text) & "les erreurs.txt") as text with write permission write "Le caractère n'a pas pu être remplacer : " & pourerreur & return to lelog starting at eof close access lelog end try set mavar to new end remplace[/CODE] [/QUOTE]
Insérer les citations…
Vérification
Publier votre réponse
Forums
Développement
Raccourcis et automatisation
Renommer fichiers en masse puis les déplacer dans un dossier parent
Haut
Bas