gpt4 book ai didi

macos - NSWorkspace iconForFile : how to detect the generic folder icon?

转载 作者:行者123 更新时间:2023-12-03 17:01:54 25 4
gpt4 key购买 nike

我正在查询一些现有文件夹的图标。我正在尝试做:

[[NSWorkspace sharedWorkspace] iconForFile:targetPath]

对于我得到的通用图标:

<__NSArrayM 0x6080004533b0>(
<NSIconRefImageRep:0x608000093c90 iconRef=0x405 size:128x128 pixels:128x128>,
<NSIconRefImageRep:0x608000283ed0 iconRef=0x405 size:128x128 pixels:256x256>,
<NSIconRefImageRep:0x608000096580 iconRef=0x405 size:256x256 pixels:256x256>,
<NSIconRefImageRep:0x60800009d290 iconRef=0x405 size:256x256 pixels:512x512>,
<NSIconRefImageRep:0x60800028d6b0 iconRef=0x405 size:512x512 pixels:512x512>,
<NSIconRefImageRep:0x60800028e4c0 iconRef=0x405 size:48x48 pixels:48x48>,
<NSIconRefImageRep:0x60800028da70 iconRef=0x405 size:36x36 pixels:36x36>,
<NSIconRefImageRep:0x60800028eb50 iconRef=0x405 size:36x36 pixels:72x72>,
<NSIconRefImageRep:0x60800028f820 iconRef=0x405 size:32x32 pixels:32x32>,
<NSIconRefImageRep:0x60800028f6e0 iconRef=0x405 size:32x32 pixels:64x64>,
<NSIconRefImageRep:0x60800028f780 iconRef=0x405 size:18x18 pixels:18x18>,
<NSIconRefImageRep:0x60800028bdb0 iconRef=0x405 size:18x18 pixels:36x36>,
<NSIconRefImageRep:0x60800028f7d0 iconRef=0x405 size:16x16 pixels:16x16>,
<NSIconRefImageRep:0x608000285a50 iconRef=0x405 size:16x16 pixels:32x32>,
<NSIconRefImageRep:0x608000080b90 iconRef=0x405 size:512x512 pixels:1024x1024>
)

如何区分文件夹是否具有常规的“通用”图标,还是自定义的图标?

最佳答案

文件夹图标存储在文件夹内名为“Icon\r”的不可见文件中。因此,检查这一点的简单方法如下:

func folderHasCustomIcon(path: String) -> Bool {
let iconPath = NSString.pathWithComponents([path, "Icon\r"])
return NSFileManager.defaultManager().fileExistsAtPath(iconPath)
}

folderHasCustomIcon("/Users/stefan/Desktop/foo") // true
folderHasCustomIcon("/Users/stefan/Desktop/bar") // false

~/Desktop/foo~/Desktop/bar 都存在。我使用 Finder 的“文件信息”窗口为 foo 提供了一个自定义图标。

关于macos - NSWorkspace iconForFile : how to detect the generic folder icon?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35015723/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com