Skip to content

Instantly share code, notes, and snippets.

@tonyedwardspz
Created July 18, 2023 10:47
Show Gist options
  • Save tonyedwardspz/683b58555555724912759e3b6a560fc0 to your computer and use it in GitHub Desktop.
Save tonyedwardspz/683b58555555724912759e3b6a560fc0 to your computer and use it in GitHub Desktop.
Move files with matching names into their own sub folder within the current directory - Used to help move from Audible to Audiobookshelf
#!/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