Applescript变量作为文件夹

Applescript变量作为文件夹,applescript,Applescript,我正在尝试编写一个AppleScript,它接收一组文件(需要注意的是,它们并不都在同一个文件夹中),并将每个文件重命名为其所在文件夹的名称。到目前为止,我已经得到了下面的内容,但我得到了一个错误,上面写着“无法获取1的容器” 出现此错误的原因是您试图获取索引变量a 基本上,缺少一行来获取对文件的引用,您需要将文件的名称设置为文件夹的名称 tell application "Finder" set all_files to every item of (choose file with

我正在尝试编写一个AppleScript,它接收一组文件(需要注意的是,它们并不都在同一个文件夹中),并将每个文件重命名为其所在文件夹的名称。到目前为止,我已经得到了下面的内容,但我得到了一个错误,上面写着“无法获取1的容器”


出现此错误的原因是您试图获取索引变量
a

基本上,缺少一行来获取对文件的引用,您需要将文件的名称设置为文件夹的名称

tell application "Finder"

    set all_files to every item of (choose file with prompt "Choose the Files you'd like to rename:" with multiple selections allowed) as list

    repeat with a from 1 to length of all_files
        set a_file to item a of all_files
        set folder_name to name of container of a_file
        set name of a_file to folder_name
    end repeat
end tell
注意:请注意,代码将删除文件的所有扩展名

tell application "Finder"

    set all_files to every item of (choose file with prompt "Choose the Files you'd like to rename:" with multiple selections allowed) as list

    repeat with a from 1 to length of all_files
        set a_file to item a of all_files
        set folder_name to name of container of a_file
        set name of a_file to folder_name
    end repeat
end tell