Skip to content

Instantly share code, notes, and snippets.

@torch2424
Last active February 18, 2017 09:20
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 torch2424/f87b3a02227e487edfc4e18b52b65b90 to your computer and use it in GitHub Desktop.
Save torch2424/f87b3a02227e487edfc4e18b52b65b90 to your computer and use it in GitHub Desktop.
A bash script for getting the different file names between two folders. This is useful for removing Files that are named wrong in Hyperspin setups
#/bin/bash
# http://stackoverflow.com/questions/26935515/in-linux-how-to-compare-two-directories-by-filename-only-and-get-list-of-result
# How to read bash script flags: http://stackoverflow.com/questions/14447406/bash-shell-script-check-for-a-flag-and-grab-its-value
if [ "$#" -ne 4 ]; then
# Not Enough Params, Show Usage
echo "Rom/Snap Folder Compare"
echo "USAGE: [script.sh] [folder 1] [folder 2] [file exenstions of folder 1] [file extensions of folder two]"
echo "NOTE: Extensions should have no '.', and folders should have no trailing slash"
exit 0
fi
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
folder1=$1
folder2=$2
ext1=$3
ext2=$4
for fullfile in ${folder1}/*.$ext1
do
#echo "$fullfile fullfile"
filename=$(basename "$fullfile")
#echo "$filename file"
extension="${filename##*.}"
#echo "$extension ext"
cleanfilename="${filename%.*}"
#echo "$cleanfilename base"
if ! [ -a "${folder2}/$cleanfilename.$ext2" ]
then
echo $fullfile
fi
done
IFS=$SAVEIFS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment