你好先生......我可能会问我如何可以检索使用C#A列出目录?我是能够建立我的TreeView和检索的所有文件和文件夹在我的闪存驱动器,但是当我尝试检索在C盘的所有文件或驱动器D:它给了我一个错误,因为我试图打开文件夹,如限制系统卷和其他文件夹中,有一个限制,打开...当我循环,当我遇到的文件夹,我只是将跳过它并不能检索文件夹的名称是可能的吗?请帮我这...预先感谢...
我有这样的错误,当我尝试运行我的检索文件夹的代码,这是错误的
这是列出所有文件夹
A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
Access to the path 'D:\$RECYCLE.BIN\S-1-5-21-3717064836-2505550092-2449041842-1014\' is denied.
Access to the path 'D:\ae1a6083e25e839c285e48eaaff1ee\' is denied.
A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
Access to the path 'D:\System Volume Information\' is denied.
代码
{C}
这将列出每个文件夹内的文件
public void listFiles(string location) {
// MessageBox.Show(location);
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(location);
try
{
foreach (System.IO.FileInfo f in dir.GetFiles("*.*"))
{
try
{
//LOAD FILES
ListViewItem lSingleItem = listView1.Items.Add(f.Name);
//SUB ITEMS
lSingleItem.SubItems.Add(Convert.ToString(f.Length));
lSingleItem.SubItems.Add(f.Extension);
}
catch (Exception e)
{
MessageBox.Show("Error in files " + e.Message);
}
}
}
catch (Exception e)
{
MessageBox.Show("Error in files " + e.Message);
Console.WriteLine(e.Message);
}
}