Do I need to check if directory/file exist or not?
c#, directory, file
Solution
You don't need to check if the directory already exists, the method does it for you. If you check on MSDN :
Any and all directories specified in path are created, unless they already exist or unless some part of path is invalid. The path parameter specifies a directory path, not a file path. If the directory already exists, this method does not create a new directory, but it returns a DirectoryInfo object for the existing directory.
Problem
Which one code is better? Code1: ``` if (!Directory.Exists("DirectoryPathHere")) Directory.CreateDirectory("DirectoryPathHere"); ``` Code2: ``` Directory.CreateDirectory("DirectoryPathHere"); ``` I think Code2 because as I saw it not gives any error and its not making new folder when the folder already exists, so I though that checking for folder existence is useless. Right?