I am trying to determine whether a given path points to a file or a directory. Currently my logic is very plain and involves the following check
if (sourcePath.Contains(".")) // then treat this path as a file
The problem above is that folder names can have periods in them too. I would like to be able to ascertain that a given path is that of a file without having to try and instantiate a filestream type and attempting to access it or anything like that.
Is there someway to do this?
Thanks in advance
You could use the File.Exists method:
So:
There’s also the Directory.Exists method and the following example is given in the documentation: