Solved

vb.net - sub directories issue

Posted on 2011-09-21
5
259 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

911 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now