Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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