File size: 2,567 Bytes
723f28c
 
 
 
 
1bb0e3e
e935c01
1bb0e3e
 
 
 
 
e935c01
1bb0e3e
 
 
723f28c
3d59d93
5e40011
 
3d59d93
 
 
 
5e40011
 
3d59d93
 
 
723f28c
 
e935c01
723f28c
 
 
 
 
 
 
e935c01
723f28c
 
1bb0e3e
723f28c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1bb0e3e
 
 
 
 
 
723f28c
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env bash

: <<'END'


bash zip.sh --stage 0 --stop_stage 0 \
--min_date 2025-04-28 \
--target_dir E:/Users/tianx/HuggingDatasets/nx_noise/data/noise/en-PH \
--debug true


bash zip.sh --stage 0 --stop_stage 0 \
--min_date 2025-04-28 \
--target_dir E:/Users/tianx/HuggingDatasets/nx_noise/data/noise/en-PH \
--debug false


bash zip.sh --stage 0 --stop_stage 0 \
--min_date 2022-04-28 \
--target_dir /data/tianxing/HuggingDatasets/nx_noise/data/speech/nx-speech/en-PH \
--debug true


bash zip.sh --stage 0 --stop_stage 0 \
--min_date 2022-04-28 \
--target_dir /data/tianxing/HuggingDatasets/nx_noise/data/speech/nx-speech/en-PH \
--debug false


END


# params
system_version="windows";
verbose=true;
stage=0 # start from 0 if you need to start from data preparation
stop_stage=9


min_date="2025-04-28"
target_dir="E:/Users/tianx/HuggingDatasets/nx_noise/data/noise/en-PH"

debug=true;

# parse options
while true; do
  [ -z "${1:-}" ] && break;  # break if there are no arguments
  case "$1" in
    --*) name=$(echo "$1" | sed s/^--// | sed s/-/_/g);
      eval '[ -z "${'"$name"'+xxx}" ]' && echo "$0: invalid option $1" 1>&2 && exit 1;
      old_value="(eval echo \\$$name)";
      if [ "${old_value}" == "true" ] || [ "${old_value}" == "false" ]; then
        was_bool=true;
      else
        was_bool=false;
      fi

      # Set the variable to the right value-- the escaped quotes make it work if
      # the option had spaces, like --cmd "queue.pl -sync y"
      eval "${name}=\"$2\"";

      # Check that Boolean-valued arguments are really Boolean.
      if $was_bool && [[ "$2" != "true" && "$2" != "false" ]]; then
        echo "$0: expected \"true\" or \"false\": $1 $2" 1>&2
        exit 1;
      fi
      shift 2;
      ;;

    *) break;
  esac
done


if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ]; then
  $verbose && echo "stage 0: zip run"

  target_date=$(date -d "$min_date" +%s)

  cd "$target_dir" || { echo "无法进入目录: $target_dir"; exit 1; }

  # do it. ...

  # 遍历所有子目录
  for dir in */; do
      dir_name=${dir%/}

      if [[ $dir_name =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
          dir_date=$(date -d "$dir_name" +%s 2>/dev/null)

          if [ -n "$dir_date" ] && [ "$dir_date" -ge "$target_date" ]; then
              if [ "${debug}" == "true" ]; then
                echo "[DEBUG] zip -r ${dir_name}.zip $dir_name"
              else
                echo "zip -r ${dir_name}.zip $dir_name"
                zip -r "${dir_name}.zip" "$dir_name"
              fi
          fi
      fi
  done

fi