Just a suggestion :

And do you really need to use file.exits() to check for directory. 
If you use file.mkdir()* it will return true if directory is created else false in case of failure. 
And if directory is present it simply returns false.

yes i know not exactly as stated in question. But couldn't hurt to try.