Results 1 to 4 of 4

Thread: Is there an API to replace the FileSystemObject.GetFolder(strFoderPath)???

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2001
    Location
    CA
    Posts
    22

    Question Is there an API to replace the FileSystemObject.GetFolder(strFoderPath)???

    Is there an API to replace the FileSystemObject.GetFolder(strFolderPath) function - (referencing the MS Scripting Runtime dll)???

    I want to be able to get a folder object to be able to loop through the subfolders and files like the FileSystemObject lets you do. I just do not want to have to include the dll file so I want to be able to do it through the API. Does anyone know if this is possible??

    Thanks for any help!
    --Nick

  2. #2
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    You could try the VB function Dir, or the API functions FindFirstFile, FindNextFile and FindClose.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2001
    Location
    CA
    Posts
    22
    Thanks a whole lot. I think that is going to work perfectly.

    PS. What is the FindClose() api used for?
    --Nick

  4. #4
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Here is a function that I wrote a while back to do exactly that, it returns all the subdirectories in one array and the the filenames in another array both passed to the GetDirectoryContents function....

    VB Code:
    1. Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
    2. Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
    3. Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
    4. Private Type FILETIME
    5.         dwLowDateTime As Long
    6.         dwHighDateTime As Long
    7. End Type
    8.  
    9. Private Type WIN32_FIND_DATA
    10.         dwFileAttributes As Long
    11.         ftCreationTime As FILETIME
    12.         ftLastAccessTime As FILETIME
    13.         ftLastWriteTime As FILETIME
    14.         nFileSizeHigh As Long
    15.         nFileSizeLow As Long
    16.         dwReserved0 As Long
    17.         dwReserved1 As Long
    18.         cFileName As String * 260
    19.         cAlternate As String * 14
    20. End Type
    21.  
    22. Private Const FILE_ATTRIBUTE_DIRECTORY = &H10
    23.  
    24. Private Sub Form_Load()
    25.  Dim sF() As String
    26.  Dim sD() As String
    27.  Dim iCt As Integer
    28.  
    29.  GetDirectoryContents "C:\*.txt", sF, sD
    30.  
    31. Debug.Print "************FILES************"
    32.  
    33.  For iCt = LBound(sF) To UBound(sF)
    34.  
    35.     Debug.Print sF(iCt)
    36.  
    37.  Next iCt
    38.  
    39. Debug.Print "************FOLDERS************"
    40.  
    41.  For iCt = LBound(sD) To UBound(sD)
    42.  
    43.     Debug.Print sD(iCt)
    44.    
    45.  Next iCt
    46.  
    47. End Sub
    48.  
    49. Function GetDirectoryContents(strDirectory As String, strFiles() As String, strDirectories() As String) As Integer
    50.  Dim hFile As Long
    51.  Dim iFileCt As Long, iDirCt As Long
    52.  Dim iNext As Long
    53.  Dim wfd As WIN32_FIND_DATA
    54.  
    55.  hFile = FindFirstFile(strDirectory, wfd)
    56.  
    57.  If hFile Then
    58.    
    59.     ReDim strDirectories(0)
    60.     ReDim strFiles(0)
    61.    
    62.     Do
    63.    
    64.     If wfd.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY Then
    65.    
    66.         ReDim Preserve strDirectories(iDirCt)
    67.         strDirectories(iDirCt) = Left$(wfd.cFileName, InStr(1, wfd.cFileName, Chr(0)) - 1)
    68.         iDirCt = iDirCt + 1
    69.    
    70.     Else
    71.        
    72.         ReDim Preserve strFiles(iFileCt)
    73.         strFiles(iFileCt) = Left$(wfd.cFileName, InStr(1, wfd.cFileName, Chr(0)) - 1)
    74.         iFileCt = iFileCt + 1
    75.    
    76.     End If
    77.    
    78.     wfd.cFileName = String(260, Chr(0))
    79.     iNext = FindNextFile(hFile, wfd)
    80.    
    81.     Loop Until iNext = 0
    82.    
    83.     FindClose hFile
    84.    
    85.  End If
    86.  
    87.  GetDirectoryContents = iFileCt + iDirCt
    88.  
    89. End Function
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width