我正在编写一个Applescript,它会提示用户选择一个文件夹,然后在该文件夹上运行脚本。该脚本运行,基本上将文件分类到文件夹中。在脚本的末尾,我希望删除空文件夹。
这个脚本运行得很好,直到我想删除最后的空文件夹。
下面是选择该文件夹的内容:
tell application "Finder"
set packageFolder to (choose folder with prompt "Please choose your
logo package folder") as string
end tell
下面是删除空文件夹的代码:
tell application "Finder"
repeat with oneFolder in (get folders of packageFolder)
if (count items) of oneFolder is 0 then delete oneFolder
end repeat
end tell
我得到以下错误:
结果:
错误“无法获取|”“Macintosh HD:Users:michael: Desktop:徽标程序包脚本测试:\”的每个文件夹。“编号-1728,来自“Macintosh HD:Users:michael: Desktop: Logo Package Script Test:”的每个类cfol»
我在这里做错了什么?
发布于 2018-08-10 03:09:59
这对我在最新版本的macOS高塞拉上有效
set packageFolder to (choose folder with prompt "Please choose your
logo package folder") as string
tell application "Finder"
set theFolders to folders of entire contents of folder packageFolder
repeat with i from 1 to count of theFolders
set thisFolder to item i of theFolders
if (count of items of thisFolder) is equal to 0 then
delete thisFolder
end if
end repeat
end tell
发布于 2018-08-10 04:07:53
这就是最终有效的方法:
on killEmpty(fol)
tell application "Finder"
repeat with f in (get fol's folders)
my killEmpty(f)
end repeat
if (count items of fol) is 0 then delete fol
end tell
end killEmpty
tell application "Finder"
repeat with f in (get folders of folder packageFolder)
my killEmpty(f)
end repeat
end tell
我在这里找到了这个解决方案:https://discussions.apple.com/message/20188767#message20188767
再次感谢大家。对于措辞不准确的问题,我很抱歉。
https://stackoverflow.com/questions/51773931
复制相似问题