下面是一个使用AppleScript的示例代码,该代码可以根据文件名将文件整理到文件夹中。
-- 获取选定的文件
set selectedFiles to selection
-- 创建文件夹
set newFolder to (choose folder with prompt "选择新文件夹") as text
-- 遍历选定的文件
repeat with selectedFile in selectedFiles
-- 获取文件名
set fileName to name of selectedFile
-- 获取文件的扩展名
set fileExtension to name extension of selectedFile
-- 创建目标文件夹路径
set destinationFolder to newFolder & fileName & "/"
-- 检查目标文件夹是否存在,如果不存在则创建
tell application "Finder"
if not (exists folder destinationFolder) then
make new folder at newFolder with properties {name:fileName}
end if
end tell
-- 移动文件到目标文件夹
tell application "Finder"
move selectedFile to folder destinationFolder
end tell
end repeat
使用上述代码,您可以选择要整理的文件,然后选择要创建的新文件夹。代码将根据文件名创建一个与文件名相同的文件夹,并将每个文件移动到相应的文件夹中。