无法通过Applescript获取列表中文件夹的项目

发布于 2024-12-18 22:03:37 字数 231 浏览 4 评论 0原文

我没有通过此代码获取图像文件夹内的文件。如何在给定变量(文件列表)中获取该文件的名称?

set p to "/Users/sumeet/Desktop/images/"

set a to POSIX file p

set filelist to (names of items of (POSIX file a))

-- file "Macintosh HD:usr:local:bin:"

I am not getting the file inside the images folder through this code. How can I get that file's name in the given variable (filelist)?

set p to "/Users/sumeet/Desktop/images/"

set a to POSIX file p

set filelist to (names of items of (POSIX file a))

-- file "Macintosh HD:usr:local:bin:"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

横笛休吹塞上声 2024-12-25 22:03:37

这将起作用:

set a to "Macintosh HD:Users:sumeet:Desktop:images:" as alias
tell application "Finder"
    set filelist to name of every file in a
end tell

您必须告诉 Finder 来获取项目列表。此外,Finder 只接受 alias 路径,因此您必须将 unix 路径更改为别名 (aaa:aaa:aaa:) 格式。

你也可以这样做:

tell application "Finder"
        set filelist to name of every file in folder "images" of desktop
    end tell

This will work :

set a to "Macintosh HD:Users:sumeet:Desktop:images:" as alias
tell application "Finder"
    set filelist to name of every file in a
end tell

You have to tell Finder to get the list of items. Also Finder only takes alias paths, so you have to change the unix path to an alias (aaa:aaa:aaa:) format.

You could also do it this way :

tell application "Finder"
        set filelist to name of every file in folder "images" of desktop
    end tell
诗笺 2024-12-25 22:03:37
set p to "/Users/sumeet/Desktop/images/"
set a to POSIX file p
tell application "Finder" to set filelist to name of items of folder a

你犯了一些错误。首先,您尝试获取 file 对象 (a) 的 POSIX 文件。您只使用一次。其次,当您实际指的是项目名称时,您使用了项目名称。您的方式在语法上更有意义,但 Applescript 不正确。第三,您必须要求 Finder 为您执行此操作,因为您想要查看文件系统。

set p to "/Users/sumeet/Desktop/images/"
set a to POSIX file p
tell application "Finder" to set filelist to name of items of folder a

You had a few mistakes. First, you tried to take the POSIX file of a file object (a). You only use this once. Second, you used names of items when you actually meant name of items. Your way makes more sense grammatically, but is incorrect Applescript. Third, you have to ask Finder to do this for you, since you want to look at the file system.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文