Creating file trees

As seen on the home page, the easiest way to create a FileTree is to call FileTree with the path to a directory on disk.

using FileTrees

taxi_dir = FileTree("taxi-data")
taxi-data/
├─ 2019/
│  ├─ 01/
│  │  ├─ green.csv
│  │  └─ yellow.csv
│  └─ 02/
│     ├─ green.csv
│     └─ yellow.csv
└─ 2020/
   ├─ 01/
   │  ├─ green.csv
   │  └─ yellow.csv
   └─ 02/
      ├─ green.csv
      └─ yellow.csv

But a FileTree does not have to reflect files on a disk. You can "virtually" create a tree using the maketree function:

maketree("mydir" => ["foo" => ["baz"], "bar"])
mydir/
├─ foo/
│  └─ baz
└─ bar

You can also construct a tree with nodes that have values!

t1 = maketree("mydir" => ["foo" => [(name="baz", value=42)], "bar"])
mydir/
├─ foo/
│  └─ baz (Int64)
└─ bar
get(t1["foo"]["baz"])
42

Another neat way of constructing a tree is to use touch to create files in an empty FileTree.

t = maketree("mydir"=>[])

for i=1:3
    for j=1:2
        global t = touch(t, "$i/$j/data.csv"; value=rand(10))
    end
end
t
mydir/
├─ 1/
│  ├─ 1/
│  │  └─ data.csv (10-element Array{Float64,1})
│  └─ 2/
│     └─ data.csv (10-element Array{Float64,1})
├─ 2/
│  ├─ 1/
│  │  └─ data.csv (10-element Array{Float64,1})
│  └─ 2/
│     └─ data.csv (10-element Array{Float64,1})
└─ 3/
   ├─ 1/
   │  └─ data.csv (10-element Array{Float64,1})
   └─ 2/
      └─ data.csv (10-element Array{Float64,1})

This last method is slower and is not recommended if you are creating thousands of files.