Skip to main content
1 of 4
alancalvitti
  • 15.2k
  • 3
  • 27
  • 93

Try this recursive query which is linear-time in input (timing study here)

prefixTrie := 
 Query[GroupBy[First], If[First@# == {}, First@#, byPrefix[#]] &, 
  Rest]

Variations on the above are possible and useful (see Antonov's Trie page here developed in 2013 but without Dataset).

For simplicity the above assumes filenames have been split into path component lists, eg "a/b/c" --> {"a","b","c"} after import:

flatFiles = FileNames["*.gsheet", "~/Google Drive/...", Infinity] // Dataset

Then:

flatFiles[All, StringSplit[#, "/"] &][prefixTrie]
alancalvitti
  • 15.2k
  • 3
  • 27
  • 93