110,535
社区成员
发帖
与我相关
我的任务
分享
if (Directory.Exists(path))
{
Utils.SetAttributesNormal(new DirectoryInfo(path));
Directory.Delete(path, true);
}
Directory.CreateDirectory(path);
public static bool IsFileInUse(string fileName)
{
bool inUse = true;
if (File.Exists(fileName))
{
FileStream fs = null;
try
{
fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.None);
inUse = false;
}
catch (Exception e)
{
Console.WriteLine(e.Message.ToString());
}
finally
{
if (fs != null)
{
fs.Close();
}
}
return inUse; //true表示正在使用,false没有使用
}
else
{
return false; //文件不存在则一定没有被使用
}
}