返回首页

你好先生......我可能会问我如何可以检索使用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);

            }

        

        }

 

回答

评论会员:游客 时间:2012/02/04
。您正试图读取所有文件的位置-但是你不必访问到所有这些imgsrc=]
。Madzmar25
评论会员:游客 时间:2012/02/04
是的,我知道我找到了如何排除特别是隐藏所有不必要的文件夹...但由于某些原因,它包括这个文件codepreae1a6083e25e839c285e48eaaff1ee/pre/code,并从它的属性,它不具有隐蔽性,读,系统为基础,压缩属性,现在我不知道为什么我不能打开它......IM做这种检查,如果该文件夹是有效的,被列入{的C4}但它仍然列出文件夹,当我尝试打开它,它给了我一个错误,我不知道如何解决这个...我不知道如何排除这种类型的文件...有没有办法找出如果我可以"打开"文件