使用 AppleScript 获取完整目录内容
我需要将文件夹及其子文件夹的全部(可见)内容作为列表获取。这可能吗?
I need to get the entire (visible) contents of a folder and its subfolders as a list. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看看这有多容易,
如果您想要一个文件名列表,那么您可以这样做是
的,整个内容完全按照您所说的进行 - 但它很容易让人窒息
大文件夹,并且需要很长时间。没关系
小事情,例如从您的文件夹中提取一种类型的所有文件
知道只会包含少量文件。
递归方法也很好用——但它使用“列表文件夹”,并且
它的字典列表表明它已被弃用,我们不应该使用它
不再有。
see how easy this can be
if you want a list of file names then you could do this
Yes, entire contents does exactly what you say -- but it easily chokes on
large folders, and takes forever. It's OK for
small things, like extracting all the files of one kind out of a folder you
know will only contain a small number of files.
The recursive method also works well -- but it's using "list folder", and
the dictionary listing for it says it's deprecated and we shouldn't use it
any more.
我确信有一个 shell 命令可以更快地完成此操作,但这是纯 Applescript 中的一种方法,可以让您完全控制要显示的信息的格式。
顺便说一句,还有许多文件列表应用程序可以比 Applescript 更快地完成此操作。
更新:作为本次讨论的结果,该函数再次出现,但这次使用更新的 API。这可能需要一些清理工作,但它可以轻松地对我的桌面进行编目(这对我来说是一个很深很深的文件夹):
I'm sure there is a shell command that can do this faster, but here is one way in pure Applescript that gives you total control over formatting what info you would like displayed.
On a side note, there are also a number file listing applications that can do this faster than Applescript.
UPDATE: As a result of this discussion, here is the function again, but this time using the updated API. This could probably could use some cleaning up, but it works cataloging my Desktop handily enough (and that's a deep, deep folder for me):
哇,这已经很晚了,但我检查了一下,它有效。
Wow this is quite late but I checked and it works.
对于那些不关心脚本的紧凑性但关心巨大速度的人来说,AsObjC 版本(由 @Shane Stanley 编写,谢谢):
For those who care not about the compactness of the script, but the huge speed, the AsObjC version (written by @Shane Stanley, thanks):