What is the maximum allowed depth of sub-folders?

24,452

Solution 1

The limit is not on the depth of the nested subdirectories (you could have dozens of them, even more), but on the file systems and its quotas.

Also having very long file paths is inconvenient (and could be slightly inefficient). Programmatically, a file path of several hundreds or even thousands of characters is possible; but the human brain is not able to remember such long file paths.

Most file systems (on Linux) have a fixed limit to their number of inodes.

Some file systems behave poorly with directories containing ten thousand entries (e.g. because the search is linear not dichotomic). And you have hard time to deal with them (e.g. even ls * gives too long output). Hence, it could be wise to have /somepath/a/0001 ... /somepath/z/9999 instead of /somepath/a0001 ... /somepath/z9999

If you have many thousands of users each with his directory, you might want to e.g. group the users by their initials, e.g. have /some/path/A/userAaron/images/foobar and /some/path/B/userBasile/images/barfoo etc. So /some/path/A/ would have only hundreds of subdirectories, etc...

A convenient rule of thumb might be: avoid having more than a few hundreds entries -either subdirectories or files- in each directory.

Some web applications store small data chunk in individual rows of a SQL databases and use files (whose name might be generated) for larger data chunks, storing the filepath in the database. Having millions of files with only a few dozen bytes in most is probably not efficient.

Some sysadmins are also using quotas on filesystems.

Solution 2

In Windows, there is a limit for 260 characters in any path. This includes filenames, so a file cannot have more characters than 260-directory path length.

This means that you could have quite a lot of subdirectories, but as you go deeper, the maximum filename gets shorter.

Solution 3

Something else that's very important is performance. With Windows if you start to get over 5k files it starts to get slow, 10k it is crawling and 50k becomes totally unusable!

Share:
24,452
Jo E.
Author by

Jo E.

Updated on December 31, 2020

Comments

  • Jo E.
    Jo E. over 3 years

    At first I wanted to ask "What is the maximum allowed sub-folder for a windows OS"

    But then I figured maybe my web hosting provider isn't on windows but on linux or something else. So I'm asking what are the possible maximum allowed sub-folder for all major OS that a Web Hosting Provider would usually use. (Would it be safe to say Linux, Mac, or Windows?)

    Then again, based on your experiences, do web hosting sites create a limit to the number of subfolders we can make?

    (Why this? Because I want each user to have their very own folder for easy access to their images. Would that be ok? Or is it bad practice? Still new to programming.)

  • Jo E.
    Jo E. about 11 years
    Thanks @basilestarynkevitch! Your answer explained a lot! And thank you for the grouping tip. I'll try to create a system with that procedure in mind.
  • Basile Starynkevitch
    Basile Starynkevitch about 11 years
    Most web hosting are not Windows based... On Linux, the limit is much bigger (at least 1024, and probably much more).
  • carlpett
    carlpett about 11 years
    @Basile: That is true. Yet, the question was "all major OS". While Linux is probably much more common, I know of dozens of hosting companies that provide Windows
  • carlpett
    carlpett about 11 years
    @BasileStarynkevitch: On linux, there are far more available file systems, and it is the filesystem which will dictate this. For instance, you could use NTFS on your linux installation (could, not should). In that case, you'd be back to max 260 character paths... For more common filesystems, such as ext2 or ext3, the limit is actually 32k
  • Jake Wilson
    Jake Wilson about 6 years
    Funny enough I remember back in the Windows XP days (maybe this is still the case?) the number of Fonts you could install was limited to the combined filename lengths of the font files. Pretty ridiculous way to limit something.
  • Zachary Vance
    Zachary Vance almost 4 years
    Good answer, the word 'dichotomic' does not mean what you think though.
  • Basile Starynkevitch
    Basile Starynkevitch almost 4 years
    In French it does.