I have a path and I need to determine if it is a directory or file.
Is this the best way to determine if the path is a file?
string file = @'C:\Test\foo.txt'; bool isFile = !System.IO.Directory.Exists(file) && System.IO.File.Exists(file);
For a directory I would reverse the logic.
string directory = @'C:\Test'; bool isDirectory = System.IO.Directory.Exists(directory) && !System.IO.File.Exists(directory);
If both don’t exists that then I won’t go do either branch. So assume they both do exists.
Use:
and check whether the returned
FileAttributesresult contains the valueFileAttributes.Directory: