c#出现对路径的访问被拒绝异常
voidFindFiles(DirectoryInfodir,stringFileName){FileInfo[]files=dir.GetFiles(FileName)...
void FindFiles(DirectoryInfo dir,string FileName)
{
FileInfo[] files=dir.GetFiles(FileName);//查找所有文件并在ListView中显示
if(files.Length!=0)
{
foreach(FileInfo aFile in files)
{
ListViewItem lvi;
lvi=new ListViewItem();
lvi.SubItems.Add(aFile.Name);
lvi.SubItems.Add(aFile.FullName);
lvi.SubItems.Add(aFile.Length.ToString());
lvi.SubItems.Add(aFile.LastWriteTime.ToShortDateString());
this.listView1.Items.Add(lvi);
}
}
DirectoryInfo[] dirs=dir.GetDirectories();//查找子文件夹中的匹配文件
if(dirs.Length!=0)
{
foreach(DirectoryInfo aDir in dirs)
{
FindFiles(aDir,FileName);
}
}
}
private void Start_Click(object sender, EventArgs e)
{
DirectoryInfo aDir = Directory.CreateDirectory(comboBox1.Text);
FindFiles(aDir, textBox1.Text);
}
出现路径访问被拒绝 请问怎么调试 展开
{
FileInfo[] files=dir.GetFiles(FileName);//查找所有文件并在ListView中显示
if(files.Length!=0)
{
foreach(FileInfo aFile in files)
{
ListViewItem lvi;
lvi=new ListViewItem();
lvi.SubItems.Add(aFile.Name);
lvi.SubItems.Add(aFile.FullName);
lvi.SubItems.Add(aFile.Length.ToString());
lvi.SubItems.Add(aFile.LastWriteTime.ToShortDateString());
this.listView1.Items.Add(lvi);
}
}
DirectoryInfo[] dirs=dir.GetDirectories();//查找子文件夹中的匹配文件
if(dirs.Length!=0)
{
foreach(DirectoryInfo aDir in dirs)
{
FindFiles(aDir,FileName);
}
}
}
private void Start_Click(object sender, EventArgs e)
{
DirectoryInfo aDir = Directory.CreateDirectory(comboBox1.Text);
FindFiles(aDir, textBox1.Text);
}
出现路径访问被拒绝 请问怎么调试 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询