Does this need an isDirectory() check? Or is the dir guaranteed to be directory? Otherwise listFiles will return null if dir is not a folder.