About
This project attempts to rename a collection of .mp4 files using a wordlist from two different folders. The script reads filenames from a text file, gathers video files from a target directory, sorts it out and then renames each file sequentially based on the wordlist order.
#!/bin/bash
cd -- /home/TonySoprano /File_Rename_Project
IFS=$'\n' read -r -d '' -a wordlist < <( cat Prepped.txt && printf '\0')
cd -- /mnt/c/Users/gabagool /dwhelper/"Courses"
echo "Renaming files in "$PWD""
shopt -s nocaseglob
myFiles=(*.mp4)
IFS=$'\n' read -r -d '' -a my_array < <(printf "%s\n" "${myFiles[@]}"| sort -V && printf '\0')
count=0
for i in "${my_array[@]}";
do
mv -v "$i" "${wordlist[$count]}"
((count++))
done
Current Workflow + Structure
Changes into a directory to read a wordlist file.
It loads the contents of that file into an array, to prevent word splits.
It then changes into a second directory containing video files.
Enables case insensitive globbing, collects all
.mp4files, sorts them using version.Takes each mp4 file and is replaced with chosen wordlist.
The program is messy and here are my weak spots I’ve found to improve on
pathfinding (cd):
cdis repeated twice so it feels like the main cause of the messy looking program.shopt -s nocaseglob; myfiles=(*.mp4):
Were placed inside the code to math .mp4/.MP4 and createdmyfilesvariable to make easier to index.
Is there anything that I have not considered?
Context:
I was getting frustrated from file naming on Windows and got tired of right clicking. This prompted me to pick up programming, but I did not expect this to cost me three weeks of my health and sleepless nights just to shave off some time. It was worth it in end.
cd -- /home/TonySoprano /File_Rename_Project(with two arguments) supposed to do? Or is that a typo and should becd -- /home/TonySoprano/File_Rename_Project? \$\endgroup\$