2017-04-26 55 views
0

我正在尝试编写一个AppleScript,它将文件选择(需要注意的是,它们并不全部位于同一个文件夹中),将每个文件重命名为它所在文件夹的名称。远远我有下面的内容,但我得到一个错误,其中显示“无法获取1的容器”。从< 1.AppleScript变量作为文件夹

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 folder_name to container of a 
     set file_name to folder_name 
    end repeat 
end tell 

回答

0

错误号-1728>的发生是因为你试图让索引变量a

基本上是一个行丢失拿到引用文件的container,你想将该文件的名称设置为文件夹的名称

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 

注意:请注意,代码会删除文件的所有扩展名。

相关问题