How do you delete all the contents of a directory without deleting the directory itself? I want to basically empty a folder yet leave it (and the permissions) intact.
in swift 2.0:
if let enumerator = NSFileManager.defaultManager().enumeratorAtPath(dataPath) {
while let fileName = enumerator.nextObject() as? String {
do {
try NSFileManager.defaultManager().removeItemAtPath("\(dataPath)\(fileName)")
}
catch let e as NSError {
print(e)
}
catch {
print("error")
}
}
}