Re: [AS] Un script pour renommer un fichier

Page principale
Supprimer ce message
Répondre à ce message
Auteur: Madert Pascal via Applescript_fr
Date:  
À: La liste AppleScript Francophone
CC: Madert Pascal
Sujet: Re: [AS] Un script pour renommer un fichier
Hello,

J'en sui là.
Le script fonctionne, mais j'aimerais récupérer dans une variable le nom du dossier dans lequel se trouve le fichier.
Exemple :
Le chemin d'accès original : Macintosh HD:Users:moi:Downloads:Dossier:ModText.xlsx
Je voudrais récupérer "Dossier" dans une variable pour le mettre à la place de "nomcourt" dans : set NewFileName to nomcourt & "-" & NouveauTexte & "." & lextension

Belle journée.
Pascal

on open fileName -- vérification de la nature du paramètre
    if class of fileName is list then set fileName to first item of fileName
    set filePath to fileName as text -- retourne le chemin d'accès Hfs
    tell application "Finder"
        set theFileName to name of fileName
        set theFilePath to fileName as string
        set extens to fileName -- recupere l'extension du fichier
        set lextension to name extension of extens
        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 theFileName
        set nomcourt to (items 1 thru -2 of elements) as string
        -- set ancien_nom to nomcourt -- nom sans extension
        set AppleScript's text item delimiters to sauv --restaurer la variable delimiteur
    end tell

    
    tell application "Microsoft Excel"
        activate
        open fileName
        select cell "H2"
        set theDate to value of active cell as date
        set shortDate to short date string of theDate -- "09/23/2016"
        set AppleScript's text item delimiters to {"/"}
        -- set Parties to every text item of shortDate
        set Parties1 to third text item of shortDate
        set Parties2 to second text item of shortDate
        set Parties3 to first text item of shortDate
        set parties to Parties1 & "-" & Parties2 & "-" & Parties3
        -- set AppleScript's text item delimiters to {"-"}
        set NouveauTexte to parties as string
        set NewFileName to nomcourt & "-" & NouveauTexte & "." & lextension
        set value of cell "B2" to theFileName
        set value of cell "B3" to theFilePath
        set value of cell "B4" to NewFileName
        set L to length of theFilePath
        set R to 0 as integer
        repeat with i from 1 to L
            if character i of theFilePath = ":" then
                if R < i then
                    set R to i
                end if
            end if
        end repeat

        
        set R to R - 1
        set chemin to text from character 1 to R of theFilePath
        set chemin2 to chemin & ":" & NewFileName
        set value of cell "B5" to chemin2
        do shell script "mv -n " & quoted form of POSIX path of theFilePath & space & quoted form of POSIX path of chemin2
    end tell
end open
_______________________________________________
Applescript_fr mailing list
Applescript_fr@???
http://listes.patpro.net/mailman/listinfo/applescript_fr