-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilenames.sh
executable file
·114 lines (100 loc) · 2.34 KB
/
filenames.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
#!/bin/bash
RESET='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
if [ "$#" == "0" ] || [ "$1" == "--help" ] || [ "$1" == "-h" ]
then
echo "usage: $(basename "$0") <path> [OPTION]"
echo "option:"
echo " -v verbose output"
echo "description: checks recursivley for bad filenames"
exit 0
fi
is_verbose=0
err=0
err_files=0
wrn=0
wrn_files=0
DIR="$1"
if [ "$2" == "-v" ] || [ "$2" == "--verbose" ]
then
is_verbose=1
fi
if [ ! -d "$DIR" ]
then
echo "Error: path does not exist '$DIR'"
exit 1
fi
function err() {
echo -e "[${RED}-${RESET}] $1"
}
function ok() {
echo -e "[${GREEN}+${RESET}] $1"
}
function wrn() {
echo -e "[${YELLOW}!${RESET}] $1"
}
function check_files() {
local match=$1
local mode=$2
lines="$(find "$DIR" -name "$match" | wc -l)"
if [ "$lines" != "0" ]
then
if [ "$is_verbose" == "1" ]
then
find "$DIR" -name "$match"
else
find "$DIR" -name "$match" | head -n 3
if [ "$lines" -gt "3" ]
then
echo "..."
fi
fi
if [ "$mode" == "warning" ]
then
wrn "Warning: found $lines invalid file names matching '$match'"
wrn_files="$((wrn_files + lines))"
wrn="$((wrn + 1))"
else
err "Error: found $lines invalid file names matching '$match'"
err_files="$((err_files + lines))"
err="$((err + 1))"
fi
fi
}
for ((i=0;i<10;i++))
do
check_files "*($i).png"
done
check_files "* Kopie.*"
check_files "*invalid encoding*"
check_files "* *" "warning"
dupe_case="$(find . | tr '[:upper:]' '[:lower:]' | sort | uniq -d | wc -l)"
if [ "$dupe_case" -ne "0" ]
then
err "found $dupe_case duplicated filenames when ignoring case:"
err_files="$((err_files + dupe_case))"
err="$((err + 1))"
if [ "$is_verbose" == "1" ]
then
find . | tr '[:upper:]' '[:lower:]' | sort | uniq -d
else
find . | tr '[:upper:]' '[:lower:]' | sort | uniq -d | head -n 3
if [ "$dupe_case" -gt "3" ]
then
echo "..."
fi
fi
fi
if [ "$wrn" != "0" ]
then
wrn "$wrn_files wrong files names ($wrn warnings)"
fi
if [ "$err" != "0" ]
then
err "$err_files wrong files names ($err errors)"
exit 1
fi
ok "all file names valid"
exit 0