objective-c – 在Cocoa中查找文件的上次访问日期

objective-c – 在Cocoa中查找文件的上次访问日期,第1张

概述是否可以使用 cocoa在mac中获取文件/文件夹最后访问日期? struct stat output; //int ret = stat([[[openPanel filenames] lastObject] UTF8String], &output); int ret = stat([[[openPanel filenames] lastObject] fileSystemRe 是否可以使用 cocoa在mac中获取文件/文件夹最后访问日期?
struct stat output;    //int ret = stat([[[openPanel filenames] lastObject] UTF8String],&output);    int ret = stat([[[openPanel filenames] lastObject] fileSy@R_404_6563@Representation],&output);    // error handling omitted for this example    struct timespec accesstime = output.st_atimespec;    NSDate *aDate = [NSDate dateWithTimeIntervalSince1970:accesstime.tv_sec];    NSLog(@"Access Time %d,%@",ret,aDate);

根据上面的代码,我尝试了UTF8String和fileSy@R_404_6563@Representation,但两者都给了我当前的日期和时间.如果我做错了,请告诉我.

解决方法 使用stat系统调用的C方式将在Objective-C中工作.

例如

struct stat output;int ret = stat(afilePath,&output);// error handling omitted for this examplestruct timespec accesstime = output.st_atime;

您应该通过将-fileSy@R_404_6563@Representation发送到包含该路径的Nsstring来获取afilePath.

另一种获得所需方法的方法是在指向所需文件的文件URL之前构造NSURL,并使用-resourceValuesForKeys:error:获取NSURLContentAccessDate资源值.

总结

以上是内存溢出为你收集整理的objective-c – 在Cocoa中查找文件的上次访问日期全部内容,希望文章能够帮你解决objective-c – 在Cocoa中查找文件的上次访问日期所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1236520.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存