Applescript 选择特定扩展名的文件

发布于 2024-09-25 11:51:30 字数 388 浏览 1 评论 0原文

我的添加到 itunes 脚本正在尝试添加不支持的类型的文件,例如 jpg/txt/.thumb 等

我想更具体地使用下面的代码仅选择 mp3 和 mp3。米4a

tell application "Finder" to set fPaths to paragraphs of ((files of entire contents of iTunesFolder) as Unicode text)

 repeat with thisFilePath in fPaths
    --processing code goes here
    -- maybe I need an if file extension is in... type condition?

 end repeat

My add to itunes script is trying to add files of unsupported types such as jpg/txt/.thumb etc

I would like to be a bit more specific with the below code to only select mp3 & m4a

tell application "Finder" to set fPaths to paragraphs of ((files of entire contents of iTunesFolder) as Unicode text)

 repeat with thisFilePath in fPaths
    --processing code goes here
    -- maybe I need an if file extension is in... type condition?

 end repeat

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

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

发布评论

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

评论(1

南笙 2024-10-02 11:51:30

我不确定你对第一行做了什么。但如果您可以将 thisFilePath 强制转换为 Finder 项目,则应该能够获得扩展名。该属性称为名称扩展。我已经用桌面上的文件对此进行了测试:

copy {"pdf", "scpt"} to validExtensions

tell application "Finder" to set fPaths to files of desktop

repeat with thisFilePath in fPaths
    if name extension of thisFilePath is in validExtensions then
        display dialog thisFilePath as string
    end if
end repeat

它将仅显示那些具有 validExtensions 中列出的扩展名的文件。

I’m not sure what you’re doing with that first line. But if you can coerce thisFilePath into a Finder item, you should be able to get the extension. The property is called name extension. I’ve tested this with the files on my desktop:

copy {"pdf", "scpt"} to validExtensions

tell application "Finder" to set fPaths to files of desktop

repeat with thisFilePath in fPaths
    if name extension of thisFilePath is in validExtensions then
        display dialog thisFilePath as string
    end if
end repeat

It will display only those files that specifically have an extension listed in validExtensions.

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