gpt4 book ai didi

swift - 在 Swift 2.2 中查找系统上文件或目录的所有者

转载 作者:行者123 更新时间:2023-11-30 13:14:50 25 4
gpt4 key购买 nike

如何在 Swift 中找出文件或目录的所有者?我知道 NSFileOwnerAccountName 可以解决这个问题,但我找不到如何使用它。

目标是创建一个 if/else 子句。如果所有者是某个名称,则继续。如果没有,就不要。

干杯!

最佳答案

不太关注我写的 String(NSStrings ) 和 AnyObjects 代码

var fileManager = NSFileManager.defaultManager();
var documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]

let destinationPath:NSString = documentsPath.stringByAppendingString("/48630772.pdf")
var username : String = " ";
if(fileManager.fileExistsAtPath(destinationPath as String))
{

var attributes = try fileManager.attributesOfItemAtPath(destinationPath as String)

username = attributes[NSFileOwnerAccountName] as! String
print(username)

}

现在您可以检查用户名的字符串值

关于swift - 在 Swift 2.2 中查找系统上文件或目录的所有者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38341450/

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