-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete-raws.sh
More file actions
executable file
·60 lines (47 loc) · 1.3 KB
/
delete-raws.sh
File metadata and controls
executable file
·60 lines (47 loc) · 1.3 KB
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
#!/bin/bash
#
# delete-raws.sh
# ==============
# Script expects JPGs and RAWs in different directories (called DIR/jpg and DIR/raw). It deletes
# all RAW images which don't have equivalent image in jpeg dir. Images are considered equivalent if
# they have same name (except the extension).
#
# usage: delete-raws.sh DIR
function usage(){
echo "usage delete-raws.sh DIRECTORY"
}
if [ $# -ne 1 ]; then
usage
exit 1
fi
DIRECTORY=$1
JPG_DIR=$DIRECTORY/jpg
RAW_DIR=$DIRECTORY/raw
if [ ! -d $JPG_DIR -o ! -d $RAW_DIR ]; then
echo "Directory $DIRECTORY doesn't have jpg and raw subdirs."
echo "Exiting without any action."
exit 2
fi
FILES_TO_REMOVE=""
for f in $RAW_DIR/* ; do
RAW_NAME=$(basename $f)
FILENAME="${RAW_NAME%.*}"
if [ ! \( -f $JPG_DIR/$FILENAME.JPG -o -f $JPG_DIR/$FILENAME.jpg \) ]; then
FILES_TO_REMOVE="$FILES_TO_REMOVE $f"
fi
done
if [ -z "$FILES_TO_REMOVE" ] ; then
echo "Nothing to remove."
exit 0
fi
echo "Following files will be removed:"
echo "$FILES_TO_REMOVE"
echo "The script will remove $(echo "$FILES_TO_REMOVE" | wc -w)/$(ls -l $RAW_DIR | wc -l) RAW files. Do you want to continue?"
answer=""
until [ "$answer" = "y" -o "$answer" = "n" ]; do
read -p "[y/n]: " answer
done
if [ $answer = "n" ]; then
exit 0;
fi
rm $FILES_TO_REMOVE