This could be simplified:

exists/types checks are redundant, if the target directory already exists (and is a directory) then createDirectories will not complain, it will only fail if the file exists and is not a directory, or if it can not make the directory.