r/AskProgramming • u/iorgfeflkd • Aug 03 '26
Other Is there any reason I shouldn't make a program that creates millions of nested empty folders?
This is, unfortunately, the most efficient way I can think of to solve a problem right now. Is there any way doing that would make my system unstable? This would be written in python and run in WSL (Ubuntu within Windows)
edit: I get the message this is a bad idea.
0
Upvotes
14
u/soundman32 Aug 03 '26
What i s the actual problem? You want to see what happens when your disk fills up?
3
u/ericbythebay Aug 03 '26
Lots of reasons, starting with it is generally a bad design. What problem are you actually trying to solve?
65
u/its_a_gibibyte Aug 03 '26
This is the epitome of an XY problem
https://en.wikipedia.org/wiki/XY_problem
More than likely you need a different solution to a different problem entirely. You didn't describe your initial problem, so we're only guessing at what you want to do. My guess is that sqlite will solve your data storage problem though and be far more efficient.
35
u/BranchLatter4294 Aug 03 '26
Whatever problem you are trying to solve, this is likely the wrong approach. But go for it. Let us know what happens.
4
u/aocregacc Aug 03 '26
it's going to use a bunch of disk space, folders aren't free.
If the folders are regularly indexed by some search tool it'll slow that down too.
3
u/AlwaysHopelesslyLost Aug 03 '26
"This is, unfortunately, the most efficient way I can think of to solve a problem right now"
Why not tell us what the problem is and we can tell you whether there is a more efficient way to do it?
3
u/eruciform Aug 03 '26
Likely a misuse of a file system as a database
Also its possible to fill up a disk drive with empty directories due to inodes taking space and possibly slowing it to a crawl
This is probably a terrible idea no matter the problem you're trying to solve
2
u/netroxreads Aug 03 '26
POSIX (and likely NT) puts a limit to how long a path can be. If you nest them millions of times, it will stop at its MAX LIMIT which is usually around 2,024 characters from what I recall and won't let you nest more folders.
2
u/Old_Cat_16 Aug 03 '26
I don’t know what problem you’re trying to solve, but I applaud you for coming up with a solution and checking for potential concerns.
A lot of folks (junior and senior engineers alike) can get hang up on identifying a perfect solution first, and end up not solving anything at all.
If you are doing this for a personal project, I say try it out, see what’s the worst could happen (besides of running out of disk space). Live and learn!
2
u/thedevguy-ch Aug 03 '26
If you're on a windows machine there is a max file oath length that you'll hit eventually
2
u/ZilderZandalari Aug 03 '26
I''ve run into tens of millions of files in hundreds of thousands of folders. Most anything dealing with that sees it as torture. Browsing is fine, but a search takes an hour...
Don't do this...
Fun fact: zipping 80k empty folders results in a 40mb file. 7-zip gets the same folders down to 2mb.
2
u/SirMarkMorningStar Aug 03 '26
Sounds like you accidentally invented hashing. While some of these responses may leave you feeling dumb, this is actually pretty smart. The wrong solution, mind you, but a smart one.
2
u/SeriousPlankton2000 Aug 03 '26
https://www.man7.org/linux/man-pages/man0/limits.h.0p.html
{PATH_MAX}
Maximum number of bytes the implementation will store as a
pathname in a user-supplied buffer of unspecified size,
including the terminating null character. Minimum number the
implementation will accept as the maximum number of bytes in
a pathname.
Minimum Acceptable Value: {_POSIX_PATH_MAX}
Minimum Acceptable Value: {_XOPEN_PATH_MAX}
1
u/m2thek Aug 03 '26
Sounds like you're writing a virus
1
u/stewsters Aug 03 '26
Yeah it could make it unstable, but you can fix it by removing them.
What problem are you trying to solve? It's unlikely this will solve it. However, sometimes you just have to go for it though.
If you are a young programmer new to the craft I suggest you just go for it. Whatever happens it will be a learning experience. You really need to nurture that fire that drives you to try new things in this, even if they are stupid.
1
u/Useful_Calendar_6274 Aug 03 '26
>the most efficient way I can think of to solve a problem right now.
what problem
1
u/GreenWoodDragon Aug 03 '26
Describe your problem. You sound very inexperienced.
1
u/Individual-Flow9158 Aug 03 '26
There's a file system path limit on Windows.
1
u/OneMonk Aug 03 '26
There is literally a type of malware called a zip bomb that does almost exactly this.
1
u/naxhh Aug 03 '26
I will go against the current and say that a common solution for file storage is to sha the file and use that as the filename.
then use the first to chars as the main folder name and the 2 next for a second.
like downloads/ac/0d/ac0dfgaf.png
that makes so your folders are not too big and unixs is a bit happier.
no idea, if that applies to your issue but wanted to share that
1
u/CypherBob Aug 03 '26
SQLite.
Easy to use, available in most languages, you get SQL.
You won't likely need anything fancy.
1
u/fugogugo Aug 04 '26
isnt that just fork bomb?
1
u/Le_9k_Redditor Aug 04 '26
Literally sounds like you want to intentionally create and run a zip bomb virus on your own machine. I made one that did exactly this with directories when I was screwing around as a teen, it's a really good way to screw up your computer and it's impossible to stop execution without physically pulling the plug if given a half decent nice level
There's no way this is the right solution for whatever you're trying to do
1
u/PrizeSyntax Aug 03 '26
Knock yourself out 😂
1
u/0jdd1 Aug 03 '26
I have a lot of these already. I can lend them to you.
More seriously, it could depend on the underlying file system, and its implementation of folders.
1
u/nwbrown Aug 03 '26
This is more concerning to me than actually creating lots of nested files.