Declare Function SendMessage& Lib "User" (ByVal hWnd%, ByVal
wMsg%, ByVal wParam%, lParam As Any) ' Note**, The author defined these constants, so you ' won't find them in API documentation, although they ' are based on values used with LB_DIR. Global Const WM_USER = &H400 Global Const LB_DIR = (WM_USER + 14) Global Const DIR_NORMALFILES = &H0 Global Const DIR_READONLY = &H8001 Global Const DIR_HIDDEN = &H8002 Global Const DIR_SYSTEM = &H8004 Global Const DIR_DIRECTORIES = &H8010 Global Const DIR_ARCHIVED = &H8020 Global Const DIR_DRIVES = &HC000 ' Add this routine to your Form's declaration section: Sub ListFiles (sFileSpec As String) Dim i As Long ' Clear existing data List1.Clear ' Add files / directories of specified types i = SendMessage(List1.hWnd, LB_DIR, DIR_DRIVES, ByVal sFileSpec) i = SendMessage(List1.hWnd, LB_DIR, DIR_DIRECTORIES, ByVal sFileSpec) i = SendMessage(List1.hWnd, LB_DIR, DIR_NORMALFILES, ByVal sFileSpec) End Sub ' In Command1_Click call the ListFiles routine: Sub Command1_Click () ' List all files from C:\Windows directory Call ListFiles("C:\WINDOWS\*.*") ' Or to list the whole tree for the current drive: ' Call ListFiles("*.*") End Sub Note: This has only been tested with VB 3 & VB 4-16, if you convert this for use with other versions please let me know.-Burt Abreu The SendMessage API provides a simple way to use a standard List Box to list files. By sending the LB_DIR message to the List Box, the list box automatically fills itself with a list of files, directories and drives. Create a new project. Add a List box (List1) and a Command button (Command1) to the form. In a .BAS module add the following declarations: Declare API |