cocoa - 如何使用 Cocoa 查找已安装卷上的可用空间量?

标签 cocoa macos volumes

我使用以下代码来确定卷上的可用空间。 该文件夹是使用 NSOpenPanel 提供的。所选项目是已安装的卷,返回的路径为\Volumes\Name

NSDictionary* fileAttributes = [[NSFileManager defaultManager] fileSystemAttributesAtPath:folder];

unsigned long long size = [[fileAttributes objectForKey:NSFileSystemFreeSize] longLongValue];    

是否有更好的方法来使用 Cocoa 确定已安装卷上的可用空间?

更新:这实际上是确定卷上可用空间的最佳方法。看起来它不起作用,但这是因为该文件夹实际上是/Volumes 而不是/Volume/VolumeName

最佳答案

提供的代码是 Cocoa 中确定卷上可用空间的最佳方法。 只需确保提供给 [NSFileManagerObj fileSystemAttributesAtPath] 的路径包含卷的完整路径。我删除了最后一个路径组件,以确保传递的是文件夹而不是文件,这导致/Volumes 被用作文件夹,而无法给出正确的结果。

NSDictionary* fileAttributes = [[NSFileManager defaultManager] fileSystemAttributesAtPath:folder];

unsigned long long size = [[fileAttributes objectForKey:NSFileSystemFreeSize] longLongValue];    

关于cocoa - 如何使用 Cocoa 查找已安装卷上的可用空间量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/263503/

相关文章:

objective-c - 使用 NSRegularExpression 命名捕获组

swift - NSViewController 委托(delegate)?

objective-c - 如何获取给定路径的文件大小?

docker 撰写 : absolute path for shared volumes in version 3

macos - 如何在Mac上的沙箱中启动另一个进程?

java - 无法初始化类 com.amazonaws.partitions.PartitionsLoader

macos - 如何阻止扩展坞中的 IntelliJ 图标弹跳,而不关闭所有应用程序的弹跳

macos - 如何在 OS X 10.4 上的 AppleScript do shell 脚本中使用 UTF-8 编码命令

多个容器之间的 Docker 命名卷