Skip to content

Instantly share code, notes, and snippets.

@tonyedwardspz
Created July 3, 2023 12:30
Show Gist options
  • Select an option

  • Save tonyedwardspz/5d9e1734af330b8f4ad50e64a678e7a8 to your computer and use it in GitHub Desktop.

Select an option

Save tonyedwardspz/5d9e1734af330b8f4ad50e64a678e7a8 to your computer and use it in GitHub Desktop.

Revisions

  1. tonyedwardspz created this gist Jul 3, 2023.
    26 changes: 26 additions & 0 deletions undo-move-files.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #!/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