2009-06-30 16 views

Respuesta

6

Salida NSFileManager 's

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

la clave que le interesa es NSFileModificationDate.

+10

Esto está en desuso en 10.5, en lugar de utilizar - (NSDictionary *) attributesOfItemAtPath: error (NSError **): (NSString *) error de ruta – aussiegeek

5

Sólo para actualizar el código:

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

La adición de esta respuesta aquí ya que este fue el primer resultado cuando buscaba la manera de hacer esto, pero si usted está utilizando rápida que te pueden gustar esta extensión:

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 
    } 


} 
Cuestiones relacionadas