Skip to content

Commit 1751c5b

Browse files
committed
Update largest folder script
1 parent fa18ea3 commit 1751c5b

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

.bin/largest_folder

+12-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ if [ "$1" = "recurse" ]; then
88
fi
99

1010
find . -type d | while read -r dir; do
11+
if ! cd "$CWD"; then
12+
echo "cwd '$CWD' doesn't exist."
13+
exit 1
14+
fi
15+
1116
if [ "$dir" = '.' ]; then
1217
continue
1318
fi
@@ -21,12 +26,14 @@ find . -type d | while read -r dir; do
2126
count="$(find . -type f | wc -l)"
2227
else
2328
count="$(find . -maxdepth 1 -type f | wc -l)"
29+
countWithFolders="$(find . -maxdepth 1 | wc -l)"
30+
((countWithFolders--))
31+
32+
# No files, but there are folders... Just ignore it.
33+
if [ "$count" -eq 0 ] && [ "$countWithFolders" -gt 0 ]; then
34+
continue;
35+
fi
2436
fi
2537

2638
echo "$count $dir"
27-
28-
if ! cd "$CWD"; then
29-
echo "cwd '$CWD' doesn't exist."
30-
exit 1
31-
fi
3239
done | sort -nr | head -"${1:-1}"

0 commit comments

Comments
 (0)