nsfilemanager - Error checking for subdirectory of Documents directory in IOS -
My app needs to create a subdirectory of the document directory. I give the code directory URL given below. The first time it creates the directory through, but fails next time because fileExistsAtPath: claims that the directory still does not exist. I know that this is present because I have set the bundle to create files in iTunes and I can see it in iTunes Any thoughts that I am doing wrong?
- (NS URL *) Application Document Directory {Return to [NSFileManager defaultManager] URLsForDirectory: NSDocumentDirectory inDomains: NSUserDomainMask] lastObject]; } - (ns URL *) ApplicationSubject directory {NSFileManager * manager = [NSFileManager defaultManager]; NSDRAEL * DOCKEYER = [self-application documentary]; DocDir = [docDir URLByAppendingPathComponent: @ "All" is Directory: Yes]; NSString * docDirPath = [docDir absolute string]; BOOL isFolder = Yes; If (([manager fileexstitap: dockdeeppath directory: & amp; amp; isFolder; & amp; amp; and; finder)) {NSER * error = zero; BOOL ret = [manager createDirectoryAtURL: docDir withIntermediateDirectories: No attributes: Zero error: & amp; Error]; If (! Ret) {NSLog (@ "Error App Support:% @", Error); Abortion (); }} Return docDir; } << Code>
You path instead of full string The full full URL returns the full path, like something "file: /// ..." while later only returns the file path.
NSString * docDirPath = [Docdir Path];
Therefore, when you are looking for a file with the path "File: /// ...." that will never exist, the check always fails . When you go to create a directory, you make it with the URL, so it works.
Comments
Post a Comment