lots of jumbled code in here, using while as it seems to be faster than for. current state is echoing the first char of each stat result, to check if it is a dir or not