weihan1 commited on
Commit
bda85f2
·
verified ·
1 Parent(s): 6ca4431

Add files using upload-large-folder tool

Browse files
Files changed (1) hide show
  1. clean_all_folders.sh +19 -23
clean_all_folders.sh CHANGED
@@ -1,6 +1,4 @@
1
  #!/usr/bin/env bash
2
- # Walk each immediate subfolder of this directory (e.g. sheep/, zebra/) and
3
- # list (or delete) partial / yt-dlp temp files.
4
  set -euo pipefail
5
 
6
  BASE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -9,31 +7,29 @@ if [[ "${1:-}" == "--delete" ]]; then
9
  DELETE=1
10
  fi
11
 
 
 
12
  find_junk() {
13
- find "$1" -type f \( \
14
- -name '*.part' -o \
15
- -name '*.ytdl' -o \
16
- -name '*.temp' -o \
17
- -name '*.tmp' -o \
18
- -name '*.frag' \
19
- \)
20
  }
21
 
22
- for dir in "$BASE"/*/; do
23
- [[ -d "$dir" ]] || continue
24
- name="$(basename "$dir")"
25
- [[ "$name" == ".cache" ]] && continue
26
-
27
- while IFS= read -r -d '' f; do
28
- if [[ "$DELETE" -eq 1 ]]; then
29
- rm -f -- "$f"
30
- echo "removed $f"
31
- else
32
- echo "$f"
33
- fi
34
- done < <(find_junk "$dir" -print0)
35
- done
36
 
37
  if [[ "$DELETE" -eq 0 ]]; then
 
38
  echo "Dry run only. Run with: $0 --delete" >&2
39
  fi
 
1
  #!/usr/bin/env bash
 
 
2
  set -euo pipefail
3
 
4
  BASE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
 
7
  DELETE=1
8
  fi
9
 
10
+ # Use -iname for case-insensitivity
11
+ # Removed the $1 argument so we can call find once on the whole BASE
12
  find_junk() {
13
+ find "$BASE" -type f \( \
14
+ -iname '*.part' -o \
15
+ -iname '*.ytdl' -o \
16
+ -iname '*.temp' -o \
17
+ -iname '*.tmp' -o \
18
+ -iname '*.frag' \
19
+ \) -not -path '*/.cache/*'
20
  }
21
 
22
+ # Process everything in one go
23
+ while IFS= read -r -d '' f; do
24
+ if [[ "$DELETE" -eq 1 ]]; then
25
+ rm -f -- "$f"
26
+ echo "Removed: $f"
27
+ else
28
+ echo "Found: $f"
29
+ fi
30
+ done < <(find_junk -print0)
 
 
 
 
 
31
 
32
  if [[ "$DELETE" -eq 0 ]]; then
33
+ echo "---"
34
  echo "Dry run only. Run with: $0 --delete" >&2
35
  fi