max length of file name

心已入冬 提交于 2019-12-06 18:06:41

问题


i am using the code below to save an image in the NSDocumentDirectory

-(BOOL)saveImage:(UIImage *)image name:(NSString *)name{

    NSString *dir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
    NSString *path = [NSString pathWithComponents:[NSArray arrayWithObjects:dir, name, nil]];

    BOOL ok = [[NSFileManager defaultManager] createFileAtPath:path contents:nil attributes:nil];

    if (!ok) {
        NSLog(@"Error creating file %@", path);
    } 
    else {
        NSFileHandle* myFileHandle = [NSFileHandle fileHandleForWritingAtPath:path];
        [myFileHandle writeData:UIImagePNGRepresentation(image)];
        [myFileHandle closeFile];
    }
    return ok;
}

the name is usually the url of where the image was downloaded.

is there a constraint on the length of the file name? you know sometimes urls may be super long...

thank you


回答1:


Taking a look at the PATH_MAX constant in syslimits.h:91

... 
#define PATH_MAX         1024   /* max bytes in pathname */
...

You can test this yourself by doing :

NSLog(@"%i", PATH_MAX);

just to make sure.



来源:https://stackoverflow.com/questions/6581433/max-length-of-file-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!