I create a directory in the viewDidLoad at the Documents folder of my app.
NSString *localDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
self.projectsLocalPath = [localDirectory stringByAppendingPathComponent:@"Projects"];
if ([[NSFileManager defaultManager] fileExistsAtPath:self.projectsLocalPath] == NO) {
[[NSFileManager defaultManager] createDirectoryAtPath:self.projectsLocalPath withIntermediateDirectories:YES attributes:nil error:nil];
}
After that, I list all files so that they appear in logs, checking wether it is a directory or not:
//----- LIST ALL FILES -----
NSArray *contentOfFolder = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:localDirectory error:nil];
for (NSString *aPath in contentOfFolder) {
NSString *fullPath = [localDirectory stringByAppendingPathComponent:aPath];
BOOL isDir;
if ([[NSFileManager defaultManager] fileExistsAtPath:fullPath isDirectory:&isDir] && isDir) {
NSLog(@"%@ - IT IS A DIR", fullPath);
}
else {
NSLog(@"%@ - IT IS NOT A DIR", fullPath);
}
}
When I first run the app, the log files list look like this:
/var/mobile/Containers/Data/Application/E3...94/Documents/Project.sqlite - IT IS NOT A DIR
/var/mobile/Containers/Data/Application/E3...94/Documents/Project.sqlite-shm - IT IS NOT A DIR
/var/mobile/Containers/Data/Application/E3...94/Documents/Project.sqlite-wal - IT IS NOT A DIR
/var/mobile/Containers/Data/Application/E3...94/Documents/Projects - IT IS A DIR
Everything is correct. But the following runs show in the logs that the Projects folder is not a directory anymore.
/var/mobile/Containers/Data/Application/E3...94/Documents/Project.sqlite - IT IS NOT A DIR
/var/mobile/Containers/Data/Application/E3...94/Documents/Project.sqlite-shm - IT IS NOT A DIR
/var/mobile/Containers/Data/Application/E3...94/Documents/Project.sqlite-wal - IT IS NOT A DIR
/var/mobile/Containers/Data/Application/E3...94/Documents/Projects - IT IS NOT A DIR
It is like it converts magically into a file... The problem is that when I want to see the directory's contents, I'm getting an error saying that it is NOT a directory.
Am I doing anything wrong? This problem is driving me nuts...
Thank you all for your help in advance.
EDIT:
At the first run, once directory is created, I download some files and save them into the newly created directory using the dropbox API: [self.restClient loadFile:plan.path intoPath:self.projectsLocalPath];. There is no error when saving files into this directory.
[self.restClient loadFile:plan.path intoPath:self.projectsLocalPath];. There is no error when saving files into this directory. - anonymous