2017-04-26 30 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 

注意:請注意,代碼會刪除文件的所有擴展名。

相關問題