I need to create a script that a user can use to run against their root directory to see what is binary and non-binary. If the files or subdirectories are non-binary, that needs to be shown in the output. The output of the script I have now shows that subdirectories with files in them are showing up as non-binary even though they are not empty.
Code:
directoryPath="/../checker"
firstLevel='./*'
secondLevel='./*/*'
thirdLevel='./*/*/*'
fourthLevel='./*/*/*/*'
if [[ -d $directoryPath ]];
then
for eachfile in $firstLevel $secondLevel $thirdLevel $fourthLevel
do
if [[ -s $eachfile ]];
then
echo "$eachfile This is a binary file"
else
echo "$eachfile This is a non-binary file"
fi
done
else
echo "$directoryPath is incorrect"
fi
Output:
./project/README.txt This is a binary file
./project/src This is a non-binary file
./project/testfile1.txt This is a binary file
**./project/src/main This is a non-binary file
./project/src/test This is a non-binary file
./project/src/main/example.jar This is a binary file
./project/src/test/example1.jar This is a binary file**