Solved

vb.net - sub directories issue

Posted on 2011-09-21
5
265 Views
Last Modified: 2012-05-12
hello there,
I have about 3500 files, all in sub directories.
I am trying to get the full path for each of the files but this code only shows about 235 files and it wont show the full path.
how can I get the full path for all 3,500 files?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        lvCount.Text = 0
        If txtPath.Text <> "" Then
            Call leGetFiles(txtPath.Text)
        Else
            Debug.Print("You need to specify a directory")
        End If
    End Sub

    Private Sub leGetFiles(ByVal strDir As String)
        Dim qFiles = IO.Directory.GetDirectories(strDir)
        Dim xFiles = IO.Directory.GetFiles(strDir)
        For Each strFile In xFiles
            Debug.Print(strFile)
            lvCount.Text = Val(lvCount.Text) + 1
        Next
        Dim qDirs = IO.Directory.GetDirectories(strDir)
        For Each y In qDirs
            Dim subFiles = IO.Directory.GetFiles(IO.Path.Combine(strDir, y))
            For Each strFile In qFiles
                Debug.Print(strFile)
                lvCount.Text = Val(lvCount.Text) + 1
            Next
        Next
    End Sub

Open in new window

0
Comment
Question by:XK8ER
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 36577380
you will get the full paths for the Debug.Print with this
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        lvCount.Text = 0
        If txtPath.Text <> "" Then
            Call leGetFiles(txtPath.Text)
        Else
            Debug.Print("You need to specify a directory")
        End If
    End Sub

    Private Sub leGetFiles(ByVal strDir As String)
        Dim qFiles = IO.Directory.GetDirectories(strDir)
        Dim xFiles = IO.Directory.GetFiles(strDir)
        For Each strFile In xFiles
            Debug.Print(Path.Combine(strDir, strFile))
            lvCount.Text = Val(lvCount.Text) + 1
        Next
        Dim qDirs = IO.Directory.GetDirectories(strDir)
        For Each y In qDirs
            Dim subFiles = IO.Directory.GetFiles(IO.Path.Combine(strDir, y))
            For Each strFile In qFiles
                Debug.Print(Path.Combine(IO.Path.Combine(strDir, y), strFile))
                lvCount.Text = Val(lvCount.Text) + 1
            Next
        Next
    End Sub

Open in new window

0
 
LVL 1

Author Comment

by:XK8ER
ID: 36577398
its not working because its showing 235 files only
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 36577422
Try EnumerateFiles instead of GetFiles. According to the documentation, the only difference between them is that EnumerateFiles is more efficient when you have a lot of files and directories, but I have found out that they sometimes behave differently. For instance, WnumerateFiles is less prone to be stopped by an UnauthorizedAccessException.

Maybe it could solve you problem.
For Each file As String In IO.Directory.EnumerateFiles(strDir, "*.*", SearchOption.AllDirectories)
    Debug.WriteLine(file)
    lvCount.Text = Val(lvCount.Text) + 1
Next

Open in new window

0
 
LVL 17

Expert Comment

by:nepaluz
ID: 36577436
you must have sub directories within the sub directories. If this is the case and you want to include these as well, what is the depth of your search? i.e how deep is the directory structure?
0
 
LVL 1

Author Comment

by:XK8ER
ID: 36577440
about 8 sud dirs
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question