How would I go about importing a drive's contents into a List View control without the use of a file list box? I know how to put them in their respective columns, I just need to know what API files and variables to use.
Printable View
How would I go about importing a drive's contents into a List View control without the use of a file list box? I know how to put them in their respective columns, I just need to know what API files and variables to use.
Is API necessary?
I think you can do that with FSO...
Yeah.. you can always do it with Scripting Library...aka File System Objects
Just to be a dickhead, I'm gonna point out that the FSO is just one part of the Scripting library - they're not one and the same thing. :DQuote:
Originally posted by moinkhan
Yeah.. you can always do it with Scripting Library...aka File System Objects
to get files from a folder:
VB Code:
Function FilesInPath(strDir As String) As String() 'returns a 0 based array with the directories in strDir Dim Count As Integer Dim sFiles() As String Dim sFile As String If Right(strDir, 1) <> "\" Then strDir = strDir & "\" sFile = Dir$(strDir, vbDirectory) Count = -1 Do If sFile <> "." And sFile <> ".." Then If (GetAttr((strDir & sFile)) And vbDirectory) <> vbDirectory Then Count = Count + 1 ReDim Preserve sFiles(Count) sFiles(Count) = sFile End If End If sFile = Dir$ Loop Until sFile = "" FilesInPath = sFiles End Function
to get folders from a folder:
VB Code:
Function DirsInPath(strDir As String) As String() 'returns a 0 based array with the directories in strDir Dim Count As Integer Dim sFiles() As String Dim sFile As String If Right(strDir, 1) <> "\" Then strDir = strDir & "\" sFile = Dir$(strDir, vbDirectory) Count = -1 Do If sFile <> "." And sFile <> ".." Then If (GetAttr((strDir & sFile)) And vbDirectory) Then Count = Count + 1 ReDim Preserve sFiles(Count) sFiles(Count) = sFile End If End If sFile = Dir$ Loop Until sFile = "" DirsInPath = sFiles End Function
oh yeah.. it gives you an array, so for example loop through files in C and adds to listbox:
dim a() as string
dim i as long
a = FilesInPath("C:\")
for i = lbound(a) to ubound(a)
list1.additem a(i)
next i