我有多个带有子文件夹的文件夹,其中包含需要用父文件夹+祖父文件夹名称标记的文件。
即Folder 1>Folder 2>File.jpg 需要重命名为Folder_1_Folder_2_File.jpg
我能够找到一个可以做到这一点的脚本,并且一直在尝试对其进行逆向工程,但没有任何运气。下面的脚本提出了两个挑战,1)它包括从根目录开始的整个路径,第二,它删除了文件的名称,因此只允许在一个文件出现错误之前重命名。我知道问题在于脚本正在重命名整个文件,我只是不知道如何继续。
tell application "Finder"
set a to every folder of (choose folder)
repeat with aa in a
set Base_Name to my MakeBase(aa as string)
set all_files to (every file in aa)
repeat with ff in all_files
set ff's name to (Base_Name & "." & (ff's name extension))
end repeat
end repeat
end tell
to MakeBase(txt)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set new_Name_Raw to every text item of txt
set AppleScript's text item delimiters to "_"
set final_Name to every text item of new_Name_Raw as text
set AppleScript's text item delimiters to astid
return final_Name
end MakeBase
谢谢!