Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

max length of file name

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

like image 887
astazed Avatar asked Jul 05 '11 10:07

astazed


People also ask

Is there a limit to file name length?

The Windows API imposes a maximum filename length such that a filename, including the file path to get to the file, can't exceed 255-260 characters.

What is the maximum file name length in Windows 10?

In Windows 10, you can enable long file name support, which allows file names up to 32,767 characters (although you lose a few characters for mandatory characters that are part of the name). To enable this, perform the following: Start the registry editor (regedit.exe)

What is the maximum length of the file name is us?

Detailed Solution. The correct answer is 8. The older MS-DOS FAT file system allows for a maximum of 8 characters in the basic file name and 3 characters in the extension, for a total of 12 characters with the dot separator. An 8.3 file name is what it's called.

Can file name be too long?

We went from an old, limited, file system to something called the New Technology File System (NTFS). NTFS took us to a point where a filename could be 255 characters long, and the file path length could potentially go up to 32,767 characters.


Video Answer


1 Answers

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.

like image 100
deanWombourne Avatar answered Oct 20 '22 02:10

deanWombourne