简体   繁体   中英

CreateDirectoryAtPath: doesn't work

I have simple code:

NSFileManager *fileManager = [NSFileManager defaultManager];

if (!fileManager) NSLog(@"Manager doesn't exist!");

if(![fileManager fileExistsAtPath:destString]) {
    if (![fileManager createDirectoryAtPath:destString withIntermediateDirectories:YES attributes:nil error:&error]){
        NSLog(@"%@", [error localizedFailureReason]);
    }
}
else NSLog(@"Exists!");

vars:

destString = file://localhost/Users/SOMEUSER/Desktop/NEWFOLDER/

When I am trying to create a folder then program writes "Exists" but on desktop doesn't exist. When I remove fileExistsAtPath: then there's no error but no directory too. Thx 4 reply!

-createDirectoryAtPath:withIntermediateDirectories:attributes:error: takes the path to create as a UNIX-style path string, and not as a file URL-style string. That is, you want to pass it a string like /Users/SOMEUSER/Desktop/NEWFOLDER/ .

Alternatively, if you're dealing with a URL-style string then you could switch to using -createDirectoryAtURL:withIntermediateDirectories:attributes:error: instead and construct an NSURL from your string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM