2009-06-30 5 views

Antwort

6

Check out NSFileManager ‚s

- (NSDictionary *)fileAttributesAtPath:(NSString *)path traverseLink:(BOOL)flag 

der Schlüssel Sie in NSFileModificationDate interessiert sind.

+10

Dies ist in 10,5 veraltet, stattdessen verwenden - (NSDictionary *) attributesOfItemAtPath: (NSString *) Pfadfehler: (NSError **) Fehler – aussiegeek

5

einfach den Code zu aktualisieren:

NSString * path = ... your path here ... 
NSDate * fileLastModifiedDate = nil; 

NSError * error = nil; 
NSDictionary * attrs = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:&error]; 
if (attrs && !error) 
{ 
    fileLastModifiedDate = [attrs fileModificationDate]; 
} 
2

diese Antwort hier hinzufügen, da dies das erste Ergebnis war, als ich gesucht, wie dies zu tun, aber wenn Sie swift verwenden könnten Sie diese Erweiterung mag:

extension NSFileManager { 

    func modificationDateForFileAtPath(path:String) -> NSDate? { 
     guard let attributes = try? self.attributesOfItemAtPath(path) else { return nil } 
     return attributes[NSFileModificationDate] as? NSDate 
    } 

    func creationDateForFileAtPath(path:String) -> NSDate? { 
     guard let attributes = try? self.attributesOfItemAtPath(path) else { return nil } 
     return attributes[NSFileCreationDate] as? NSDate 
    } 


} 
Verwandte Themen