在DirectoryInfo.GetDirectories中需要帮助 [英] Need help in DirectoryInfo.GetDirectories

查看:57
本文介绍了在DirectoryInfo.GetDirectories中需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用DirectoryInfo.GetDirectories和递归方法枚举目录中包含的目录.当我枚举驱动器(c:,d:等)中包含的目录时,就会出现问题.当我引用与项目和Visual Studio安装驱动器不同的驱动器时,它工作正常,但是,如果我引用与项目位置相同的驱动器,则该驱动器始终引用项目文件夹中的Debug文件夹,并且如果我引用了驱动器与Visual Studio安装驱动器相同,它始终是指Visual Studio安装路径中的某个位置(我不知道确切的路径).谁能帮我解决这个问题?有关信息,我使用安装在本地光盘c:上的vs2005,并将我的项目文件夹安装在本地光盘d:.

I tried to enumerate directories contained in a directory using DirectoryInfo.GetDirectories and recursive method. The problem comes when I enumerate directories contained in a drive (c:, d:, etc). When I referred a drive different from my project and visual studio installation drive, its work well, but, if I referred a drive that same with my project location, its always refer to Debug folder on my project folder, and if I referred a drive that same with visual studio installation drive, its always refer to a location inside visual studio installation path (I don''t know the exact path). Can anyone help me with this problem?. For information, I use vs2005 installed on local disc c:, and my project folder on local disc d:.

推荐答案

在此处粘贴您正在使用的代码-也许有人能够帮助您.
您是否在指定默认路径?如果没有尝试,请设置一个.
Paste the code you are using here - someone maybe able to help you.
Are you specifying a default path? If not try setting one.


''枚举所有可用和就绪的驱动器
'' Enumerate all available and ready drive(s)
<br />
<pre lang="vb.Net"><br />
For Each drvInfo As IO.DriveInfo In IO.DriveInfo.GetDrives<br />
            If drvInfo.IsReady Then<br />
                Select Case drvInfo.DriveType<br />
                    Case IO.DriveType.Fixed<br />
                        Dim aNode As TreeNode = New TreeNode<br />
                        aNode.Text = IIf(drvInfo.VolumeLabel <> "", drvInfo.VolumeLabel, "Local Disk") & "(" & drvInfo.Name.Replace("\", "") & ")"<br />
                        aNode.Tag = drvInfo.Name.Replace("\", "")<br />
                        tvwFolders.Nodes.Add(aNode)<br />
                        gatherSubDir(aNode, drvInfo.Name.Replace("\", ""))<br />
                    Case IO.DriveType.Removable<br />
                        Dim aNode As TreeNode = New TreeNode<br />
                        aNode.Text = IIf(drvInfo.VolumeLabel <> "", drvInfo.VolumeLabel, "Removable Disk") & "(" & drvInfo.Name.Replace("\", "") & ")"<br />
                        aNode.Tag = drvInfo.Name.Replace("\", "")<br />
                        tvwFolders.Nodes.Add(aNode)<br />
                        gatherSubDir(aNode, drvInfo.Name.Replace("\", ""))<br />
                End Select<br />
            End If<br />
        Next<br />
<br />
'' gatherSubDir routine<br />
Private Sub gatherSubDir(ByVal node As TreeNode, ByVal dirName As String)<br />
        Dim dInfo As IO.DirectoryInfo = New IO.DirectoryInfo(dirName)<br />
        For Each anInfo As IO.DirectoryInfo In dInfo.GetDirectories<br />
            Try<br />
                If Not anInfo.Attributes And IO.FileAttributes.Hidden Then<br />
                    Dim aNode As TreeNode<br />
                    aNode = New TreeNode<br />
                    aNode.Text = anInfo.Name<br />
                    aNode.Tag = anInfo.FullName<br />
                    node.Nodes.Add(aNode)<br />
                    gatherSubDir(aNode, anInfo.FullName)<br />
                End If<br />
            Catch ex As Exception<br />
            End Try<br />
        Next<br />
    End Sub</pre><br />
<br />


这就是我探索驱动器和目录的方式.我通过直接在Visual Studio IDE下运行尝试了它.我的最终目的是创建一个工具,以便在多个目录中找到一些类似的文件,希望我可以减少一些无用的空格.
我为我的语言感到抱歉,因为我原本是印度尼西亚语.


This is how I explore drive(s) and directories. I tried it by running directly under visual studio IDE. My final purpose is create a tool to find some similar file(s) on several directory, hopefully I can cut down some meaningless spaces used.
I''m sorry for my language, cause I''m originally an Indonesian.


最近,我意识到"C:"和"C:\"之间的区别DirectoryInfo对象的实例.使用"C:"时,其始终引用此驱动器中最后一个活动目录的路径,但是使用"C:\"时,其引用此驱动器中的根目录.
Lately, I realized the difference between "C:" and "C:\" when its passed into an instance of DirectoryInfo object. When "C:" is used, its always refer to the path of the last active directory in this drive, but when "C:\" is used, its refer to root directory in this drive.


这篇关于在DirectoryInfo.GetDirectories中需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆