Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/DeployPage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# <a href="http://shashi.biz/FileTrees.jl">FileTrees</a>

[![Build Status](https://travis-ci.org/shashi/FileTrees.jl.svg?branch=master)](https://travis-ci.org/shashi/FileTrees.jl) [![Build status](https://ci.appveyor.com/api/projects/status/6sei8e7et721usx6?svg=true)](https://ci.appveyor.com/project/shashi/filetrees-jl)
[![Coverage Status](https://coveralls.io/repos/github/shashi/FileTrees.jl/badge.svg?branch=master)](https://coveralls.io/github/shashi/FileTrees.jl?branch=master)
[![CI](https://github.com/shashi/FileTrees.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/shashi/FileTrees.jl/actions/workflows/ci.yml)
[![Coverage Status](https://coveralls.io/repos/github/shashi/FileTrees.jl/badge.svg?branch=master)](https://coveralls.io/github/shashi/FileTrees.jl?branch=master)

Easy everyday parallelism with a file tree abstraction.

Expand Down
36 changes: 19 additions & 17 deletions src/datastructure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ struct NoValue end

Copy over all fields from `tree`, but use any fields provided as keyword arguments.

FileTree(dirname::String)
FileTree(dirname::String; [sort])

Construct a `FileTree` to reflect directory from disk in the current working directory.

If `sort=true` (the default) then each level of the tree will be lexicographically sorted.
"""
struct FileTree
parent::Union{FileTree, Nothing}
Expand Down Expand Up @@ -53,25 +55,25 @@ function FileTree(t::FileTree;
FileTree(parent, name, children, value)
end

FileTree(dir) = FileTree(nothing, dir)

function FileTree(parent, dir)
children = []
parent′ = FileTree(parent, dir, children)
FileTree(dir; kwargs...) = FileTree(nothing, dir; kwargs...)

ls = readdir(dir)
cd(dir) do
children′ = map(ls) do f
if isdir(f)
FileTree(parent′, f)
else
File(parent′, f)
end
function FileTree(parent, dir; sort=true, root="")
parent′ = FileTree(parent, dir, [])
for (path, dirs, files) in walkdir(joinpath(root, dir))
for dir in dirs
push!(parent′.children, FileTree(parent′, dir; sort, root=path))
end
append!(children, children′)
for file in files
push!(parent′.children, File(parent′, file))
end
if sort
sort!(parent′.children; by=name)
end
# this might look a bit silly, but we don't care much for walkdir recursing down the tree, only that it is
# much faster than readdir + isdir/isfile when it comes to separating files from directories
break
end

parent′
parent′
end

"""
Expand Down
Loading