Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / July 2008



Tip: Looking for answers? Try searching our database.

VB: How to transverse folders/subfolders looking at each filename in     each

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Grobit - 28 Jul 2008 18:09 GMT
Hi,

Could someone please show me sample VB6 code on how to transverse
through specified directories/sub-directories, looking at each file in
each directory?

Thanks.
Richard Cole - 28 Jul 2008 20:14 GMT
>Hi,
>
[quoted text clipped - 3 lines]
>
>Thanks.
Look up DIR in the help and it gives you sample code that will transverse a
directory structure, from a given starting point, using recursion

Richard
See http://www.caravanningnow.co.uk where my caravan's for sale.
Signature

A programmer is a machine for converting coffee to software.

Tony Proctor - 29 Jul 2008 10:09 GMT
Dir$() will search through the files of a given directory. However, it's not
re-entrant, meaning that it makes it difficult to search lower-levels of
directory because it can only search one directory at a time.

Here's a slightly different way of tackling the problem:
http://groups.google.ie/group/comp.lang.basic.visual.misc/msg/8600feded860aa54?hl=en

   Tony Proctor

> Hi,
>
[quoted text clipped - 3 lines]
>
> Thanks.
小賢子 - 29 Jul 2008 10:19 GMT
> Hi,
>
[quoted text clipped - 3 lines]
>
> Thanks.

some sample Code

Function ListFilesAndDirs(ByVal sStartDir As String, frmMe As Form)
   Dim lpFindFileData As WIN32_FIND_DATA, lFileHdl  As Long
   Dim sTemp As String, sTemp2 As String, lRet As Long, iLastIndex
As Integer
   Dim strPath As String, strFolder As String

   On Error Resume Next

   '// add trailing \ to start directory if required
   If Right$(sStartDir, 1) <> "\" Then sStartDir = sStartDir & "\"

   strFolder = Mid(frmMe.Drive1, 1, 2) & "\"
   With frmMe
       .lstFiles.Clear
       .lstFolders.Clear
   End With
   sStartDir = sStartDir & "*.*"

   '// get a file handle
   lFileHdl = FindFirstFile(sStartDir, lpFindFileData)

   If lFileHdl <> -1 Then
       Do Until lRet = ERROR_NO_MORE_FILES
           strPath = Left$(sStartDir, Len(sStartDir) - 4) & "\"
           '// if it is a directory
           If (lpFindFileData.dwFileAttributes And
FILE_ATTRIBUTE_DIRECTORY) = vbDirectory Then
               'Strip off null chars and format the string
               sTemp =
StrConv(StripTerminator(lpFindFileData.cFileName), vbProperCase)
               ' make sure it is not a reference
               If sTemp <> "." And sTemp <> ".." Then
                   'add it to the tree view. Store its path as its
Key
                   frmMe.lstFolders.AddItem sTemp
               End If
           '// if it is a file
           ElseIf (lpFindFileData.dwFileAttributes And
FILE_ATTRIBUTE_NORMAL) = vbNormal Then
               sTemp =
StrConv(StripTerminator(lpFindFileData.cFileName), vbProperCase)
               If UCase(Right(sTemp, 4)) = ".TIF" Then
                  frmMe.lstFiles.AddItem sTemp
               End If
           End If
           '// based on the file handle iterate through all files and
dirs
           lRet = FindNextFile(lFileHdl, lpFindFileData)
           If lRet = 0 Then Exit Do
       Loop
   End If
   '// close the file handle
   lRet = FindClose(lFileHdl)
End Function
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.