Skip to content

Commit

Permalink
Fixes paths containing spaces + remove \
Browse files Browse the repository at this point in the history
Theses changes remove the `\` when a file or folder contains a space (just like in `tree`) and allow such folders to be traversed.
  • Loading branch information
vic1707 authored Apr 23, 2022
1 parent 5c8a6ca commit be4fd96
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions tree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ traverse() {
local directory=$1
local prefix=$2

local children=($directory/*)
local children=("$directory"/*)
local child_count=${#children[@]}

for idx in "${!children[@]}"; do
local child=${children[$idx]// /\\ }
child=${child##*/}
local child=${children[$idx]}

local child_prefix="│   "
local pointer="├── "
Expand All @@ -24,9 +23,9 @@ traverse() {
child_prefix=" "
fi

echo "${prefix}${pointer}$child"
[ -d "$directory/$child" ] &&
traverse "$directory/$child" "${prefix}$child_prefix" ||
echo "${prefix}${pointer}${child##*/}"
[ -d "$child" ] &&
traverse "$child" "${prefix}$child_prefix" ||
file_count=$((file_count + 1))
done
}
Expand Down

0 comments on commit be4fd96

Please sign in to comment.