[<] Sujet : [AS] Retirer_un_pr_éfixe_à_une_liste_de_fichie rs
De : PJ <anonyme@...>
Date : 2008-02-28 15:52:24
-- Auteur : Jacques PIOTROWSKI - France
-- Date de rédaction : 31/08/2003
-- Statut : OPEN SOURCE / G.P.L.
-- But : renommer un lot de fichiers en retirant un préfixe au nom existant.
on open liste_des_fichiers
--
-- Initialiser les constantes
--
set label_Annuler to "Annuler"
set label_Continuer to "Continuer"
set label_Reprendre to "Reprendre"
--
-- Initialiser les variables de travail
--
set racine_ok to false as boolean
tell application "Finder"
set nb_fichiers to the count items in liste_des_fichiers
end tell
--
-- Saisir un préfixe pour renommer l'ensemble des fichiers
--
set message_utilisateur to "Entrez un préfixe qui sera retiré au nom des
fichiers sélectionnés"
repeat
set reponse_utilisateur to display dialog message_utilisateur ¬
buttons {label_Continuer, label_Annuler} default button 1 ¬
with icon note default answer ""
set prefixe_saisi to text returned of reponse_utilisateur
set bouton_choisi to button returned of reponse_utilisateur
set long_prefixe to length of prefixe_saisi
if long_prefixe > 0 then
if bouton_choisi = label_Continuer then
set racine_ok to true
exit repeat -- Saisie du préfixe
end if
else
if bouton_choisi = label_Continuer then
set message_utilisateur to "Aucune information saisie !"
end if
end if
end repeat -- Saisie du préfixe
--
-- Renommer les fichiers sélectionnés
--
tell application "Finder"
repeat with un_fichier in liste_des_fichiers
get the info for the un_fichier
set useMe to the result
get the name of useMe
set ancien_nom to the result as string
set ancienne_long to length of ancien_nom
-- display dialog "ancien nom= " & ancien_nom & " ancienne
longueur= " & ancienne_long
set pos_prefixe to offset of prefixe_saisi in ancien_nom
if pos_prefixe = 1 then
set nouveau_nom to characters (long_prefixe + 1) thru
ancienne_long of ancien_nom as string
-- display dialog "nouveau nom= " & nouveau_nom
set the name of un_fichier to nouveau_nom
end if
end repeat
end tell
end open
_______________________________________________
Applescript_fr mailing list
anonyme@...
http://listes.patpro.net/mailman/listinfo/applescript_fr
Apple, AppleScript, AppleScript Studio, AppleTalk, AppleWorks, ColorSync, Finder, HyperCard, iBook, iLife, iMac, iWork, Keynote, Mac, Macintosh, Mac OS, Pages, Panther, PowerBook, Power Mac, Power Macintosh, QuickTime, Safari, Tiger, Xcode sont des marques déposées par Apple Computer, Inc., enregistrées aux Etats-Unis et dans les autres pays. Liste officielle