Bug (fixed): Error if build-script run while in current directory.

For some reason, os.path.split("__build.py") returns ("","__build.py")
Since everything but the last element is used to generate the path,
calling os.listdir("") was resulting in errors.

Also rearranged some code with no change in logic.