Append filenames with folder name [dont understand]

前端 未结 1 1835
谎友^
谎友^ 2021-01-27 18:32

Im struggling to understand how to rename(append) filenames inside a folder with the folders name. Eg, about.txt, picture.jpg, etc to become folderName-about.txt, fol

1条回答
  •  粉色の甜心
    2021-01-27 19:06

    I want all filenames inside the folder to have the folders name prepended at the beginning of the filename. Eg, about.txt to become folderName-about.txt, etc.

    Try this:

    tell application "Finder"
        ...
        set the_folder to name of createNewStructure
        repeat with this_file in (get files of entire contents of createNewStructure)
            set name of this_file to the_folder & "-" & (name of this_file)
        end repeat
    end tell
    

    The whole Script:

    set theFolder to ((path to desktop) as text) & "SCRIPT:script-copy"
    set targetFolder to ((path to desktop) as text) & "SCRIPT:script-copy-finished"
    
    display dialog "Which structure do you wish to duplicate?" buttons {"-MAIN", "-OTHER"}
    set chosenStructure to ((path to desktop) as text) & "SCRIPT:script-copy:" & button returned of result
    
    display dialog "Specify a new folder name:" default answer "John The Dog"
    set newName to (text returned of result)
    
    tell application "Finder"
        set createNewStructure to make new folder at targetFolder with properties {name:newName}
        duplicate every file of entire contents of folder chosenStructure to createNewStructure
    
        set the_folder to name of createNewStructure
        repeat with this_file in (get files of entire contents of createNewStructure)
            set name of this_file to the_folder & "-" & (name of this_file)
        end repeat
    end tell
    

    0 讨论(0)
提交回复
热议问题