Listing directory content in Visual basic 6
I have a folder called c:\myFolder. Inside the folder has 3 files, which is a.gif, b.gif,c.gif, and a folder called subFolder.
Now given the path C:\myFolder, how do get all the file name or folder name inside? And how to distinguish a folder from a file?
(I only need first level of file name, ie no need to recurse the subfolder)
Re: Listing directory content in Visual basic 6
Use FSO, file system objects.
to differentiate file and folder use fso.file and fso.folder...
Re: Listing directory content in Visual basic 6
Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LB_DIR = &H18D
Private Const DDL_DIRECTORY = &H10
Private Const DDL_ARCHIVE = &H20
Private Const DDL_EXCLUSIVE = &H8000
Private Sub Command1_Click()
List1.Clear: List2.Clear
' Directories
SendMessage List1.hwnd, LB_DIR, DDL_EXCLUSIVE Or DDL_DIRECTORY, ByVal "C:\myfolder\*.*"
' Files
SendMessage List2.hwnd, LB_DIR, DDL_EXCLUSIVE Or DDL_ARCHIVE, ByVal "C:\myfolder\*.*"
End Sub
Re: Listing directory content in Visual basic 6
You can also use Dir(), sample available in code bank. Take your pick.
Re: Listing directory content in Visual basic 6
Re: Listing directory content in Visual basic 6
Re: Listing directory content in Visual basic 6
A series of forum sections at the bottom of the main page where members have posted useful code.
Did you try my example?
Re: Listing directory content in Visual basic 6
When you do an advanced search limit your search to the VBForums CodeBank section for Visual Basic 6 by scrolling down the list and selecting it
Re: Listing directory content in Visual basic 6
Re: Listing directory content in Visual basic 6
Wow...thanks for all the great help. And Hack, thanks for you code also:)
CodeBank is really a wonderful virtual bank!