forum

Home / DeveloperSection / Forums / Creating a directory in Documents in iOS

Creating a directory in Documents in iOS

Tarun Kumar 1463 12-Aug-2015

I'm creating a folder in my documents directory and I want to do it without typing out /Users/(username)/Documents/Foo/Bar

 

NSString *directoryPath = [NSString  stringWithFormat:@"%@/Documents/Foo/Bar", NSHomeDirectory()];   

 

BOOL isDir;

NSFileManager *fileManager= [NSFileManager defaultManager];

if(![fileManager fileExistsAtPath:directoryPath isDirectory:&isDir])

    if(![fileManager createDirectoryAtPath:directoryPath withIntermediateDirectories:YES attributes:nil error:NULL])

        NSLog(@"Error: Create folder failed %@", directoryPath);

 This doesn't work when I try using NSHomeDirectory() with it. But if I typed out the full path /Users/(username)/Documents/Foo/Ba it works. How can it be done to not have to know the users folder?

EDIT: directoryPath becomes

/Users/(username)/Library/Developer/CoreSimulator/Devices/FAB78255-38D2-49BE-9683-7A0676EA2288/data/Containers/Data/Application/67B0AACE-572A-4808-9535-D221AEEB9EFA/Foo/Bar

I just want /Users/(username)


Updated on 13-Aug-2015

Can you answer this question?


Answer

1 Answers

Liked By