Search code examples
linuxwindowsmacosdirectorysubdirectory

What is the maximum allowed depth of sub-folders?


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.)


Solution

  • 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.