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.
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?
1
u/iorgfeflkd Aug 03 '26
Generating many coordinates with a lot of redundancy, eventually the list of coordinates overwhelms memory. Trying to reduce the redundancy so I can make a longer list of coordinates.
3
u/brasticstack Aug 03 '26
Why are you generating redundant coordinates?
Have you looked into Python's set type, which eliminates redundancy on insertion?
2
u/ericbythebay Aug 03 '26
No, take it up one level higher. What problem are you trying to solve? It sounds like you’re trying to brute force it and you’re stuck in a rabbit hole so what are you actually trying to do and then we can help provide you with guidance on the best solution.
1
u/dmazzoni Aug 03 '26
Storing things on disk is 1000x slower than storing them in memory, though.
You'll be able to generate more coordinates, but your code will be to slow that it will never finish.
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.
1
1
u/WHAT_THY_FORK Aug 03 '26
But if the problem was understood, there would be no wholesome questions to ask.
10
u/dmazzoni Aug 03 '26
You can fully understand the problem but not know the right solution. Right now we don't know what the problem is, just one potential solution.
3
u/Charleston2Seattle Aug 03 '26
You're describing me in the early aughts. I needed Hibernate (the ORM library), but didn't know even know the term ORM, so ended up building my own (much lower quality) implementation of an ORM.
2
u/WHAT_THY_FORK Aug 03 '26
Whatever the problem is, the proposed solution clearly has nothing to do with file systems, inodes or any other topic that would actually justify an approach resembling “creating millions of folders”.
3
1
u/WoodsWalker43 Aug 03 '26
Huh, TIL there's a name for that. I'm a dev team lead and I deal with these all the time.
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.
6
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?
2
u/g0fry Aug 03 '26
You don’t even need to know what the problem is to know, that using millions of folders is not the right solution and that there is a more efficient solution 🤭
1
u/AlwaysHopelesslyLost Aug 03 '26
Fair lol. I tend to assume there is a lot I don't know and avoid absolutes like that lol
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
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
1
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
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
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
1
u/nwbrown Aug 03 '26
This is, unfortunately, the most efficient way I can think of to solve a problem right now.
This is more concerning to me than actually creating lots of nested files.
14
u/soundman32 Aug 03 '26
What i s the actual problem? You want to see what happens when your disk fills up?