首页 > 代码库 > 如何检测文件夹是否可写可读
如何检测文件夹是否可写可读
private bool CheckFolderWriteable(string path)
{
if (!Directory.Exists(path))
{
Directory.CreateDirectory(Server.MapPath(path));
return true;
}
try
{
string testFilePath = string.Format("{0}/test{1}{2}{3}{4}.txt", path, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, DateTime.Now.Millisecond);
FileStream TestFile = System.IO.File.Create(testFilePath); // 可读
TestFile.WriteByte(Convert.ToByte(true)); // 可写
TestFile.Close();
System.IO.File.Delete(testFilePath);
return true;
}
catch
{
return false;
}
}
如何检测文件夹是否可写可读