2009-08-21 10 views

Respuesta

61

El método NSString-stringByDeletingLastPathComponent hace precisamente eso.

Se puede utilizar la siguiente manera:

NSLog(@"%@", [@"/tmp/afolder" stringByDeletingLastPathComponent]); 

Y se registrará /tmp.

14

Normalmente las URL de los archivos son del tipo NSURL. Ahora hay un método que puede usar para tomar el directorio principal: NSURL *parentDirectory = [fileURL URLByDeletingLastPathComponent];

1

Debe usar la URL para las ubicaciones de los archivos. Si tiene una ruta como String, la convertiría en URL. Para Swift 3 use

let fileURL: URL = URL(fileURLWithPath: "/path/to/something") 
let folderURL = fileURL.deletingLastPathComponent() 
Cuestiones relacionadas