C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了objective-c – 在Cocoa中查找文件的上次访问日期大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
是否可以使用 cocoa在mac中获取文件/文件夹最后访问日期?
struct stat output;
    //int ret = stat([[[openPanel filenames] lastObject] UTF8String],&output);
    int ret = stat([[[openPanel filenames] lastObject] fileSystemRepresentation],&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和fileSystemRepresentation,但两者都给了我当前的日期和时间.如果我做错了,请告诉我.

解决方法

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

例如

struct stat output;
int ret = stat(aFilePath,&output);
// error handling omitted for this example
struct timespec accessTime = output.st_atime;

您应该通过将-fileSystemRepresentation发送到包含该路径的NSString来获取aFilePath.

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

大佬总结

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

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。