2

Let's say I have one directory in my filesystem, which has a number of subdirectories and files. The number of subdirectories and files in this directory runs to many tens of thousands. You'll be familiar with the significant delay you'll get in attempting to view the contents of this directory, even in a terminal.

I've seen this solution in a fair number of places: sorting that top-level list of contents into a trie-style directory structure. So, for example, if the original list was [000000.txt ... 999999.txt], then to get to the file 012345.txt, I would visit, say, ./0/1/2/3/4/012345.txt .

What I've been unable to find is a short and sweet script to generate this kind of structure. Does something exist or must I write my own? I'd like it to work like this:

$ ls
000001.txt 000002.txt ...
$ mktrie
$ ls
0/ 1/ 2/ ...
$
3
  • Is that really a B-tree? what you described sounds more like a Trie data structure Commented Dec 26, 2009 at 10:23
  • After taking a quick look at WP, yes, I think you're right. Commented Dec 26, 2009 at 10:30
  • Possible duplicate of how to stream read directory in node.js? Commented Jun 3, 2017 at 0:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.