获取文件信息出现UnauthorizedAccessException异常截取出问题的一段,想要获得文件的大小,请问有没有什么方法加个IF语句半段d.fullname的属性是否非只读?
private void Form3_Load(object sender, EventArgs e)
{
string path;
textBox1.Text = DriveInfo.GetDrives()[g].Name;
path = DriveInfo.GetDrives()[g].Name;
DirectoryInfo files = new DirectoryInfo(path);
DirectoryInfo[] dinfo = files.GetDirectories();
try
{
foreach (DirectoryInfo d in dinfo)
//if(File.Open(d.FullName, FileMode.Open).
{
File.SetAttributes(d.FullName, FileAttributes.Normal);
dataGridView1.Rows.Add(
d, File.Open(d.FullName, FileMode.Open).Length
);
}
}
catch (UnauthorizedAccessException x)
{
MessageBox.Show("NO ACCESS");
}