internal class FileUnits
{
public static CheckPath GetInfo(string path)
{
if (path == null)
{
throw new ArgumentNullException("path");
}
CheckPath checkPath = new CheckPath();
try
{
FileAttributes fileAttributes = File.GetAttributes(path);
if((fileAttributes&FileAttributes.Directory)==FileAttributes.Directory)
{
checkPath.Type = FileType.Dir;
}
else
{
checkPath.Type= FileType.File;
}
checkPath.IfExist = true;
}
catch (Exception ex)
{
bool hasEx=Path.HasExtension(path);
if (hasEx)
{
checkPath.Type = FileType.File;
}
else
{
checkPath.Type = FileType.Dir;
}
checkPath.IfExist = false;
}
return checkPath;
}
}
public class CheckPath
{
public bool IfExist { get; set; }
public FileType Type { get; set; }
}
public enum FileType
{
File=0,
Dir=1
}
}
c# .net如何判断字符串是文件夹还是路径
最新推荐文章于 2025-04-28 10:15:24 发布