Skip to content

Instantly share code, notes, and snippets.

@tonyedwardspz
Created July 3, 2023 12:30
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/5d9e1734af330b8f4ad50e64a678e7a8 to your computer and use it in GitHub Desktop.
Save tonyedwardspz/5d9e1734af330b8f4ad50e64a678e7a8 to your computer and use it in GitHub Desktop.
Moves m4b and pdf files into the parent folder
#!/bin/bash
# Loop through all directories in the current directory
for directory in */; do
# Check if it's a directory
if [[ -d "$directory" ]]; then
# Remove trailing slash
dir_name="${directory%/}"
# Construct file names
m4b_file="${dir_name}.m4b"
pdf_file="${dir_name}.pdf"
# Check if the corresponding .m4b and .pdf files exist in the directory
if [[ -f "${directory}/${m4b_file}" ]] && [[ -f "${directory}/${pdf_file}" ]]; then
# If they do, move the .m4b and .pdf files to the current directory
mv "${directory}/${m4b_file}" ./
mv "${directory}/${pdf_file}" ./
# Remove the directory
rmdir "${directory}"
echo "Moved ${m4b_file} and ${pdf_file} out of ${directory}"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment