Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

JoelBC

macrumors 65816
Original poster
Jun 16, 2012
1,026
86
Is there a limit to the number of characters in a filename and, if yes:

1. What is the limit in HFS format [i.e. Macintosh HD:User:Documents:...]?

2. What is the limit in POSIX format [i.e. ~/Users/Documents/...]?

3. Which is better / preferred in terms of the ability to transfer file between devices so that files are not missed [i.e. not copied / not moved] because their filename length is too long?

Thanks in advance,

Joel
 

maflynn

macrumors Haswell
May 3, 2009
73,682
43,740
Searching the google, I easily came up with 255 characters for bot HFS+ POSIX file formats.

I'd say the best one is native file format for OS X, that is HFS+ is better for OSX.
 

NoBoMac

Moderator
Staff member
Jul 1, 2014
6,282
4,968
Don't forget to add into the equation the length of a pathname, which is 1024 in OS X (and generally most *nix boxes).

Sure, can have folders and files with 255 chars, but that limits number of sub-folders possible.

"Strict" POSIX is 14 characters for files, 256 for paths, but doubt one will see something setup like that in this day and age.

Code:
$ getconf _POSIX_NAME_MAX
14
$ getconf _POSIX_PATH_MAX
256
$ getconf _XOPEN_NAME_MAX
255
$ getconf _XOPEN_PATH_MAX
1024
 

Partron22

macrumors 68030
Apr 13, 2011
2,655
808
Yes
Searching the google , I easily...
I got the same answer easily by renaming a file in Finder; just keep typing until it beeps at you, then paste the result into BBEdit to get a character count.
Any extension e.g. .jpg, counts toward the limit.

HFS limit used to be 31 characters.
HFS+ limit is 255-character unicode file names
 
Last edited:

JoelBC

macrumors 65816
Original poster
Jun 16, 2012
1,026
86
Appreciate all the responses...so, to summarize to make sure I have this right:

1. HFS+ Format...the limit is 255 characters which starts with "Macintosh HD" and ends with the filename extension [i.e. .doc]. Is this correct.

2. POSIX Format...the limit is 255 characters which starts with "User" [i.e. as is User/UserName/Documents/test_file.doc] and ends with the file extension.


If this is not correct then please correct.

One last thing, why it is better to count / work in than in POSIX?

Thanks.
 

NoBoMac

Moderator
Staff member
Jul 1, 2014
6,282
4,968
Re: lengths. No, you have it wrong. Maybe I'm miss reading the post.

255 for individual file/folder name, with the path being a total of 1024 characters, with all the "/" and path prefix to a given file.

So, can build a path/structure:

/Users/myusername/<255charfoldername>/<255filenamewith.ext>

This would be a 529 character pathname with two 255 "files" (folders are really files in *nix world).
 

JoelBC

macrumors 65816
Original poster
Jun 16, 2012
1,026
86
Re: lengths. No, you have it wrong. Maybe I'm miss reading the post.

255 for individual file/folder name, with the path being a total of 1024 characters, with all the "/" and path prefix to a given file.

So, can build a path/structure:

/Users/myusername/<255charfoldername>/<255filenamewith.ext>

This would be a 529 character pathname with two 255 "files" (folders are really files in *nix world).

Appreciate the clarification which I know understand subject to the following:

1. Please confirm that the pathname DOES INCLUDE the "/" in "/Users'.

2. Please confirm that the "/" before either the folder name or filename count as part of the pathname but do not count as part of the filename.

Thx..
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.