added EnsureDirectoryExists() function