-
Notifications
You must be signed in to change notification settings - Fork 0
/
mass_renamef2.sh
61 lines (52 loc) · 1.64 KB
/
mass_renamef2.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
#!/bin/bash
# Function to get directory location from the user
get_directory_location() {
clear
echo -e "\tThis script renames a group of files. Please use with care."
read -p "$bold Where are the files located?: $normal" "FL"
}
# Function for mass renaming of files
mass_rename() {
#clear
#get_directory_location
echo -e "\n$bold These are the files located at:$normal $(cd $FL && pwd)\n$(ls $FL)\n"
cd $FL
read -p "$bold Please input what you want to change: $normal" remove
echo -e "\n\t$bold These are the files that will be changed $normal"
ls | grep "$remove"
# Confirmation step after listing files
confirm_rename
}
# Function for confirmation step
confirm_rename() {
read -p "$bold Do you want to proceed with the renaming? (Y/N): $normal" confirm
case $confirm in
Y|y|yes)
perform_rename
;;
N|n|no)
echo -e "$bold Renaming canceled. Rerunning the renaming function.$normal"
$(cd - )
get_directory_location
;;
*)
echo -e "$bold Invalid choice. Going back to the previous step.$normal"
;;
esac
}
# Function to perform mass renaming
perform_rename() {
read -p "$bold Please input what you want to add: $normal" add
ls | while read line
do
mv "$line" "$(echo -e "$line" | sed -e "s/$remove/$add/")" 2>/dev/null
done
echo -e "\n\t$bold The files have been renamed to:$normal"
ls | grep "$add"
}
# Main section
echo "This script helps you with directory operations."
# Ask for directory location
get_directory_location
# Perform mass renaming
mass_rename