-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathempty_check.sh
executable file
·180 lines (152 loc) · 3.88 KB
/
empty_check.sh
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/bash
# *********************************************************
# * Author : LEI Sen
# * Email : sen.lei@outlook.com
# * Create time : 2018-12-24 16:22
# * Last modified : 2018-12-25 15:50
# * Filename : empty_check.sh
# * Description :
# *********************************************************
## Make sure you have the foder location specified.
if [ "$1" == "" ]; then
echo "parameter 1 missing: file folder location needed!"
exit
fi
if [ "$2" == "" ]; then
echo "parameter 2 missing: file type needed!"
exit
fi
echo ""
echo "Checking empty files in folder [$1/] ..."
echo ""
file_path=$1/
file_list=$1/*.$2
fp_sub_list=$1/*
suffix=.$2
new_folder=$1_result_stats/
if [ -d "$new_folder" ]; then
echo " (removing previous summary folder... )"
rm -r "$new_folder"
echo " (...previous summary folder removed. )"
fi
mkdir "$new_folder"
echo ""
echo """ Summary folder created.
corresponding files will be saved in: ${new_folder}
"""
result_f="${new_folder}result_stats.csv"
if [ -f $result_f ]; then
rm $result_f
fi
echo "file_name,size,is_empty" > $result_f
f_num=($f_sub_list)
f_num=${#f_num[@]}
f_num="$(find ${file_path} -mindepth 1 -maxdepth 1 -type d | wc -l)"
f_index=0
f_index_true=0
for fp_sub in $fp_sub_list; do
if [ -d "$fp_sub" ]; then
sub_folder_name=${fp_sub#"$file_path"}
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>> $sub_folder_name"
f_list=$fp_sub/*.$2
let f_index=f_index+1
echo -ne "Progress: ${f_index}/${f_num} (empty: ${f_index_true}) \r"
for f in $f_list; do
f_name=${f#"$fp_sub/"}
## Get file size
f_size="$(wc -c < "$f")"
if [ $f_size -eq 0 ]; then
is_empty='Yes'
let f_index_true=f_index_true+1
#cp -r $fp_sub $new_folder
f_wo_ext=${f%"$suffix"}
cp "$f_wo_ext".* "$new_folder"
#echo $f_name
#echo -ne "Progress: ${f_index}/${f_num} (empty: ${f_index_true}) \r"
#break
else
is_empty='No'
fi
## Get final results
final_results="${f_name},${f_size},${is_empty}"
echo "${final_results}" >> $result_f
done
fi
done
echo "Progress: ${f_index}/${f_num} (empty: ${f_index_true})"
echo """
... Done.
"""
####
exit
####
prefix=$1/
suffix=.$2
new_folder=$1/result_stats/
f_num=($file_list)
file_num_total=${#f_num[@]}
f_index=0
rm -r $1/result_stats
mkdir $1/result_stats
result_file="$1/result_stats/result_stats.csv"
if [ -f $result_file ]; then
rm $result_file
fi
echo "file_name, size, is_empty" > $result_file
for file in $file_list; do
#file_name="${file/$file_path/}"
file_name=${file#"$prefix"}
file_name=${file_name%"$suffix"}
echo "$file_name"
## Get file size
file_size="$(wc -c < "$file")"
if [ $file_size == 0 ]; then
is_empty='Yes'
cp $file $new_folder
else
is_empty='No'
fi
## Get final results
final_results="${file_name}, ${file_size}, ${is_empty}"
echo "${final_results}" >> $result_file
done
echo ""
echo "Checking empty files in folder [$1/] ..."
echo ""
file_path=$1/
file_list=$1/*.$2
#echo $file_list
#cd $file_path
prefix=$1/
suffix=.$2
new_folder=$1/result_stats/
f_num=($file_list)
file_num_total=${#f_num[@]}
f_index=0
rm -r $1/result_stats
mkdir $1/result_stats
result_file="$1/result_stats/result_stats.csv"
if [ -f $result_file ]; then
rm $result_file
fi
echo "file_name, size, is_empty" > $result_file
for file in $file_list; do
#file_name="${file/$file_path/}"
file_name=${file#"$prefix"}
file_name=${file_name%"$suffix"}
echo "$file_name"
## Get file size
file_size="$(wc -c < "$file")"
if [ $file_size == 0 ]; then
is_empty='Yes'
cp $file $new_folder
else
is_empty='No'
fi
## Get final results
final_results="${file_name}, ${file_size}, ${is_empty}"
echo "${final_results}" >> $result_file
done
echo """
... Done.
"""