代码之家  ›  专栏  ›  技术社区  ›  deanWombourne

触摸一个文件-更新它的修改时间戳

  •  8
  • deanWombourne  · 技术社区  · 14 年前

    有没有一种有效的方法来更新iPad文件系统中文件的最后修改属性,即unix touch命令?

    2 回复  |  直到 14 年前
        1
  •  11
  •   deanWombourne    14 年前

    好的,我在问完问题后回答我的问题:(

    setAttributes:ofItemAtPath:error: 在NSFileManager类中,我可以在那里指定修改的时间戳。

    无论如何谢谢你!

        2
  •  8
  •   Ashley    10 年前

    更新修改时间戳(例如,在 ls -l )的 filePath 至今:

    NSError* error;
    NSFileManager* fileManager = [NSFileManager defaultManager];
    
    if (![fileManager setAttributes:@{NSFileModificationDate:[NSDate date]}
                       ofItemAtPath:filePath
                              error:&error]) {
        NSLog(@"Couldn't update modification date: %@", error);
    }