HighTechTalks DotNet Forums  

HLP: Finding file Types

VB.net microsoft.public.dotnet.languages.vb


Discuss HLP: Finding file Types in the VB.net forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Mr. B
 
Posts: n/a

Default HLP: Finding file Types - 04-17-2004 , 05:34 PM






I'm writing an app where I'm trying to look for and List all specific file
'types' found. So I point to a specific start top level Folder... and I want
to drill down through ALL sub folders to find file types (using File
Extenion).

All found DWG files are listed in "lbDwgList" Listbox.

I can get the top level and the 'immediate' level below the top level... but I
can't figure out how to keep going down X levels (ie: All sub-levels). Any
help appreciated!

Here's what I've go so far:

Imports System.IO

Public Class Form1
Inherits System.Windows.Forms.Form

Dim DWGFilPth As String ' DWG Files Path
Dim DWGfilname As String ' DWG Name
Dim DWGtestname As String ' DWG Test Name

(((#Region " Windows Form Designer generated code ")))

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
' *********
' Form Load
' *********

' *********** Start Folder Paths ***********

DWGFilPth = "P:\Projects\"
' ******************************************

' Find Plot Styles in Multiple Folders and Lists them
' Get Folder Names Listing in DWGs Path
Dim rootDi As New DirectoryInfo(DWGFilPth)

' Look for DWG's in Root DWG File Path
Dim DWGdirsRt() As String = Directory.GetFiles(DWGFilPth)
For Each DWGfilname In DWGdirsRt
DWGtestname = System.IO.Path.GetFileName(DWGfilname)
' Test for DWG files
Dim FilTest As String = DWGtestname.Remove(0, (Len(DWGtestname) - 3))
If UCase(FilTest) = "DWG" Then
lbDwgList.Items.Add(DWGtestname)
End If
Next

' Look for DWG's in Sub-Folders of DWG File Root Folder
Dim di As DirectoryInfo
For Each di In rootDi.GetDirectories
Dim DWGdirs() As String = Directory.GetFiles(DWGFilPth & di.Name)
For Each DWGfilname In DWGdirs
DWGtestname = System.IO.Path.GetFileName(DWGfilname)
' Test for DWG files
Dim FilTest As String = DWGtestname.Remove(0, (Len(DWGtestname) - 3))
If UCase(FilTest) = "DWG" Then
lbDwgList.Items.Add(DWGtestname)
End If
Next
Next

' *************
' End Form Load
' *************
End Sub

End Class


Regards,

Bruce

Reply With Quote
  #2  
Old   
Gary Milton
 
Posts: n/a

Default Re: Finding file Types - 04-17-2004 , 06:57 PM






Hi Mr B,

You need to do it using a recursive function call. Add the following
function to your form...

\\\
Private Sub GetDWGFiles(ByVal DWGFilPth As String)
' Find Plot Styles in Multiple Folders and Lists them
' Get Folder Names Listing in DWGs Path
Dim rootDi As New DirectoryInfo(DWGFilPth)

' Look for DWG's in Root DWG File Path
Dim DWGdirsRt() As String = Directory.GetFiles(DWGFilPth)
Dim DWGfilname As String
Dim DWGtestname As String
For Each DWGfilname In DWGdirsRt
DWGtestname = System.IO.Path.GetFileName(DWGfilname)
' Look for DWG's in Root DWG File Path
If DWGtestname.Length >= 3 Then
Dim FilTest As String = DWGtestname.Remove(0,
(Len(DWGtestname) - 3))
' Test for DWG files
If UCase(FilTest) = "DWG" Then
lbDwgList.Items.Add(DWGtestname)
End If
End If
Next

' Look for DWG's in Sub-Folders of DWG File Root Folder
Dim di As DirectoryInfo
For Each di In rootDi.GetDirectories
AddFilesToList(di.FullName)
Next
End Sub
///

....then call the function in your Form_Load event...

\\\
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
' *********
' Form Load
' *********

GetDWGFiles("P:\Projects")

' *************
' End Form Load
' *************
End Sub
///

HTH,
Gary

"Mr. B" <User (AT) NoWhere (DOT) com> wrote

Quote:
I'm writing an app where I'm trying to look for and List all specific file
'types' found. So I point to a specific start top level Folder... and I
want
to drill down through ALL sub folders to find file types (using File
Extenion).

All found DWG files are listed in "lbDwgList" Listbox.

I can get the top level and the 'immediate' level below the top level...
but I
can't figure out how to keep going down X levels (ie: All sub-levels).
Any
help appreciated!

Here's what I've go so far:

Imports System.IO

Public Class Form1
Inherits System.Windows.Forms.Form

Dim DWGFilPth As String ' DWG Files Path
Dim DWGfilname As String ' DWG Name
Dim DWGtestname As String ' DWG Test Name

(((#Region " Windows Form Designer generated code ")))

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
' *********
' Form Load
' *********

' *********** Start Folder Paths ***********

DWGFilPth = "P:\Projects\"
' ******************************************

' Find Plot Styles in Multiple Folders and Lists them
' Get Folder Names Listing in DWGs Path
Dim rootDi As New DirectoryInfo(DWGFilPth)

' Look for DWG's in Root DWG File Path
Dim DWGdirsRt() As String = Directory.GetFiles(DWGFilPth)
For Each DWGfilname In DWGdirsRt
DWGtestname = System.IO.Path.GetFileName(DWGfilname)
' Test for DWG files
Dim FilTest As String = DWGtestname.Remove(0, (Len(DWGtestname) -
3))
If UCase(FilTest) = "DWG" Then
lbDwgList.Items.Add(DWGtestname)
End If
Next

' Look for DWG's in Sub-Folders of DWG File Root Folder
Dim di As DirectoryInfo
For Each di In rootDi.GetDirectories
Dim DWGdirs() As String = Directory.GetFiles(DWGFilPth & di.Name)
For Each DWGfilname In DWGdirs
DWGtestname = System.IO.Path.GetFileName(DWGfilname)
' Test for DWG files
Dim FilTest As String = DWGtestname.Remove(0, (Len(DWGtestname) -
3))
If UCase(FilTest) = "DWG" Then
lbDwgList.Items.Add(DWGtestname)
End If
Next
Next

' *************
' End Form Load
' *************
End Sub

End Class


Regards,

Bruce



Reply With Quote
  #3  
Old   
Mr. B
 
Posts: n/a

Default Re: Finding file Types - 04-17-2004 , 11:23 PM



With Deft Fingers, "Gary Milton" <anonymous (AT) discussions (DOT) microsoft.com> wrote:

Quote:
You need to do it using a recursive function call. Add the following
function to your form...

' Look for DWG's in Sub-Folders of DWG File Root Folder
Dim di As DirectoryInfo
For Each di In rootDi.GetDirectories
AddFilesToList(di.FullName)
Next
End Sub

HTH,
Gary
Hmmmmm....

Looks like I need to work on this... Your example only displays the folders
under the Root folder

Oh well.. thanks for the reply... I might be able to work something out.

Regards,

Bruce


Reply With Quote
  #4  
Old   
Gary Milton
 
Posts: n/a

Default Re: Finding file Types - 04-18-2004 , 06:13 AM



That was a typo - the recursion call should be...

\\\
' Look for DWG's in Sub-Folders of DWG File Root Folder
Dim di As DirectoryInfo
For Each di In rootDi.GetDirectories
GetDWGFiles(di.FullName)
Next
///

Gary

"Mr. B" <User (AT) NoWhere (DOT) com> wrote

Quote:
With Deft Fingers, "Gary Milton" <anonymous (AT) discussions (DOT) microsoft.com
wrote:

You need to do it using a recursive function call. Add the following
function to your form...

' Look for DWG's in Sub-Folders of DWG File Root Folder
Dim di As DirectoryInfo
For Each di In rootDi.GetDirectories
AddFilesToList(di.FullName)
Next
End Sub

HTH,
Gary

Hmmmmm....

Looks like I need to work on this... Your example only displays the
folders
under the Root folder

Oh well.. thanks for the reply... I might be able to work something out.

Regards,

Bruce



Reply With Quote
  #5  
Old   
Mr. B
 
Posts: n/a

Default Re: Finding file Types - 04-18-2004 , 11:03 AM



With Deft Fingers, "Gary Milton" <anonymous (AT) discussions (DOT) microsoft.com> wrote:

Quote:
That was a typo - the recursion call should be...
Aha! Excellent. Thanks Muchly.... nice to know how it's done!

Great stuff!

Regards,

Bruce


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.