我有一个路径,我需要确定它是目录还是文件.
这是确定路径是否为文件的最佳方法吗?
string file = @"C:\Test\foo.txt";
bool isFile = !System.IO.Directory.Exists(file) &&
System.IO.File.Exists(file);
对于目录,我会颠倒逻辑.
string directory = @"C:\Test";
bool isDirectory = System.IO.Directory.Exists(directory) &&
!System.IO.File.Exists(directory);
如果两者都不存在,那我就不go 做任何一个分支.所以假设它们都存在.