11 Replies Latest reply: Oct 4, 2010 8:07 PM by Richology
Richology Level 1 Level 1 (0 points)
Does anyone know:
a) how many levels of folders are permissible in Mac OS X
b) how many characters are allowed for file or folder names?

I have recently switched over to the Mac system from Windows where the I believe the maximum number of "folders within folders" (levels in the hierarchy) is 8, and the maximum number of characters for naming files or folders is 64. My main concern is that backups in Windows are truncated beyond these limits.

I've searched for answers in Apple tutorials, forums, books (etc.), and even AppleCare was not able to answer these questions.

Thank you very much!

MacBook Pro, Mac OS X (10.6.4)
  • Niel Level 10 Level 10 (268,545 points)
    how many levels of folders are permissible in Mac OS X


    Any.

    how many characters are allowed for file or folder names?


    255.

    (54098)
  • Richology Level 1 Level 1 (0 points)
    Thank you. Surprising that there is absolutely no limit on the number of folder levels and greatly appreciate the specific 255 characters information. Just want to clarify if you meant anything with the "(54098)" notation. Again, appreciate your guidance.
  • Niel Level 10 Level 10 (268,545 points)
    Just want to clarify if you meant anything with the "(54098)" notation.


    I didn't. Ignore it.

    (54145)
  • BobHarris Level 6 Level 6 (14,925 points)
    Thank you. Surprising that there is absolutely no limit on the number of folder levels and greatly appreciate the specific 255 characters information.

    There is a path length of 1024 as specified by the pathconf() function:

    PC_PATHMAX == 1024

    What this means is if you are going to pass a path to a kernel function (and many library routines), the total string length may not exceed 1024 characters.

    However, if you do something like

    mkdir a
    cd a
    mkdir b
    cd b
    mkdir c
    cd c
    mkdir d
    cd d
    etc...

    you can continue as deep as you wish, you will just need to make sure that when you access any files at the deeper levels that the string specified as the path does not exceed 1024 bytes.
  • Richology Level 1 Level 1 (0 points)
    Thank you, Bob. You hit my concern exactly where you indicated: "... you will just need to make sure that when you access any files at the deeper levels that the string specified as the path does not exceed 1024 bytes."

    Since this is "cumulative," is there any way to know when the limit has been exceeded before running into any issues down the road?

    For example, in Windows, when this limit was exceeded, that data was was truncated when attempting to backup or even just "copy and paste" to another drive.
  • BobHarris Level 6 Level 6 (14,925 points)
    While not 100%, many backup utilities, internally cd to the current directory as they walk down the directory tree, so they are only opening the filename and do not need to specify a path, or at worse specify the path as ./filename

    Your mileage may vary.

    It is actually a good idea to NOT create extremely long paths.
    Since this is "cumulative," is there any way to know when the limit has been exceeded before running into any issues down the road?

    If you are using a program that actually specifies the full path via a path string, then it will either get a file or directory not found as the path is too long, or the function will return an error if it checks the path length, or if you are unluckly, it will stop processing the long path at an exact point that happens to match a real file.

    This is all on a program by program basis.
  • Richology Level 1 Level 1 (0 points)
    Thank you again. That is extremely helpful and appreciated. ~ Rich
  • Whitecity Level 2 Level 2 (340 points)
    Out of interest, what are you doing that would cause you to worry about this?
  • Richology Level 1 Level 1 (0 points)
    Dear Whitecity, regarding your question: "Out of interest, what are you doing that would cause you to worry about this?"

    My concern is only what I mentioned above, that with the Windows OS, there are limits with the number of sub-levels. If those are exceeded, subsequent information is truncated during backups or even when copying information between disks. It's not always apparent during day-to-day usage, since there are no warnings about that if you happen to add a folder beyond that level. It becomes an issue when accessing a backup and finding that certain information is not available. Being new to OS X, I wanted to make sure I took that into account if there was any sort of similar limit.
  • BobHarris Level 6 Level 6 (14,925 points)
    FYI. I did some path length sample measurements on my MacBook.

    longest path 317 /User/harris
    longest path 283 /Library
    longest path 229 /System

    If you want to check your own system you could use a Terminal script such as:

    find / | awk '{n=length($0);if(n>longest)longest=n}END{print longest}'


    Message was edited by: BobHarris
  • Richology Level 1 Level 1 (0 points)
    Thank you for taking the time to look into this further, Bob. Since the longest path on your system is 317, that suggests it would be extremely unlikely that 1024 limit would be approached with normal usage. I'll try the script you were kind enough to provide, just to double-check. Appreciate your assistance most sincerely!