【发布时间】:2016-03-30 00:13:25
【问题描述】:
其实我有两个问题。
当我尝试获取文件夹中的文件时,如何排除 .DS_STORE、Icon 等隐藏文件? 我试过“without invisibles”,但它似乎不起作用。
如果已经存在,如何将我的 var the_new_folder 设置为现有文件夹?
感谢您的回答。
我的代码:
--
-- Get all files in a selected folder
-- For each file, create a folder with the same name and put the file in
--
tell application "Finder"
set the_path to choose folder with prompt "Choose your folder..."
my file_to_folder(the_path)
end tell
on file_to_folder(the_folder)
tell application "Finder"
-- HELP NEEDED HERE
-- HOW TO EXCLUDE HIDDEN FILES (Like Icon, .DS_STORE, etc)
set the_files to files of the_folder
repeat with the_file in the_files
-- Exclude folder in selection
if kind of the_file is not "Folder" then
set the_path to container of the_file
set the_file_ext to name extension of the_file
-- Remove extension of the file name
set the_file_name to name of the_file as string
set the_file_name to text 1 thru ((offset of the_file_ext in (the_file_name)) - 2) of the_file_name
-- Make the new folder with the file name
try
set the_new_folder to make new folder at the_path with properties {name:the_file_name}
on error
-- HELP NEEDED HERE
-- HOW TO SET the_new_folder AS THE EXISTING FOLDER
end try
-- Move the file in the new folder
move the_file to the_new_folder
end if
end repeat
end tell
end file_to_folder
tell application "Finder"
(display dialog ("It's done!") buttons {"Perfect!"})
end tell
【问题讨论】:
-
Finder 会考虑
AppleShowAllFiles首选项设置,如果密钥设置为 false,则忽略不可见文件。
标签: macos applescript