#!/bin/bash
#($SEARCH && ls -l | awk '{print $9"\t"$5}')
#ls -l displays all the files in the current directory
# ls -l | awk '{print $9"\t"$5}' displays the files name and the size in bytes in the current directory

#starting location either specificy the location or default to the local directory
#ls -l | awk '{print $9"\t"$5}'
SEARCH="cd $1"

dirrecur() {
	for D in *; do
		#check to see if the directory is empty
		FTYPE=$(file $D | awk '{print $2}')
		#echo $FTYPE
		if [ $FTYPE = "directory" ]; then
			NEWPATH="cd $D"
			#echo $NEWPATH
			#"$(ls -A $D)"
			if [ ! "$(find "$D" -maxdepth 0 -prune -empty)" ] ; then
				($NEWPATH && dirrecur)
			else
				continue
			fi
		else
			if [ $D = "*" ]; then
				continue
			else
				stat --printf="%s\n" $D
			fi
		fi
	done
	cd - > /dev/null		
}


#if there is no argument supplied, search the current directory
if [ $# -eq 0 ] ; then
	#for each thing in the current directory
	for D in *; 
	do
		#(ls -l | awk '{print $5}')
		#get the file type
		FTYPE=$(file $D | awk '{print $2}')
		#echo $FTYPE
		#if the file is a directory, need to CD to it and do the same until
		# there are no more things to loop through
		if [ $FTYPE = "directory" ]; then
			NEWPATH="cd $D"
			#echo $NEWPATH
			#-n "$(find "$D" -maxdepth 0 -prune -empty)"
			if [ ! "$(find "$D" -maxdepth 0 -prune -empty)" ] ; then
				($NEWPATH && dirrecur)
			else
				continue
			fi		
		else
			if [ $D = "*" ]; then
				continue
			else
				stat --printf="%s\n" $D
			fi
		fi
	done
	exit 1
#if there is a directory supplied, go there
else
	($SEARCH && dirrecur)
	exit 1
fi


