Skip to content

Instantly share code, notes, and snippets.

@tonyedwardspz
Created July 3, 2023 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonyedwardspz/d1d35dc4d5ce0f1c7711bc2dfe65732d to your computer and use it in GitHub Desktop.
Save tonyedwardspz/d1d35dc4d5ce0f1c7711bc2dfe65732d to your computer and use it in GitHub Desktop.
Move m4b and PDF files into a subfolder if they have the same name - Used for AudioBookShelf setup
#!/bin/bash
# Loop through all .m4b files in the current directory
for m4b_file in *.m4b; do
# Check if the file exists (in case there are no .m4b files)
if [[ -f "$m4b_file" ]]; then
# Get the filename without extension
base_name="${m4b_file%.*}"
# Check if the corresponding .pdf file exists
pdf_file="${base_name}.pdf"
if [[ -f "$pdf_file" ]]; then
# If it does, create a new directory with the base name
mkdir -p "$base_name"
# Move the .m4b and .pdf files to the new directory
mv "$m4b_file" "${base_name}/"
mv "$pdf_file" "${base_name}/"
echo "Moved ${m4b_file} and ${pdf_file} into ${base_name}/"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment