well, i think the title says it all... no FSO plz... i know the dir function can do this, but i don't know how...
Printable View
well, i think the title says it all... no FSO plz... i know the dir function can do this, but i don't know how...
What does FSO mean?
Why wouldn't you just use the File List Box control? (The intrinsic one)
Good day Eric:) This should solve your problem.
VB Code:
Private Sub Command1_Click() Dim arrFiles() As String Dim i As Long arrFiles = DirList("C:\windows\*.*") 'You need the \*.* or it won't work... For i = 0 To UBound(arrFiles) List1.AddItem arrFiles(i) Next End Sub Function DirList(strDir As String) As String() 'returns a 0 based array with the files in strDir 'Can contain a pattern such as "*.*" 'NOTE - subfolders not supported at this time Dim Count As Integer Dim sFiles() As String Dim sFile As String sFile = Dir$(strDir) Count = -1 Do Count = Count + 1 ReDim Preserve sFiles(Count) sFiles(Count) = sFile sFile = Dir$ Loop Until sFile = "" DirList = sFiles End Function
im not sure how to do it but try going here:
www.google.com
VB Code:
Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long Private Sub Command1_Click() Dim r As Long r = SendMessageStr(List1.hwnd, &H18D, &H20, "C:\*.*") End Sub
peet: That is a VERY nice little snippet of code!
:D
so many choices of code, so much use for them... now i gotta decide which one i want to use...
fso = teh file system object = teh crapQuote:
Originally posted by Kevin_0011
What does FSO mean?
Why wouldn't you just use the File List Box control? (The intrinsic one)
i don't use the file list box control because im retarded and i like having things done in code, i use the least amount of intrinsic controls i can just because it makes me feel special to do it myself (by copying other peoples codes :D)
cooooooooooooooooolness...:cool:Quote:
Originally posted by peet
VB Code:
Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long Private Sub Command1_Click() Dim r As Long r = SendMessageStr(List1.hwnd, &H18D, &H20, "C:\*.*") End Sub
Question... in
<code>
Private Declare Function SendMessageStr Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
i have an error of Object variable not set on the list1.hwnd, what is list1 supposed to be?
Reason I ask, I was thinking of making a small program just to search my cd's and make a list of every cd, and whats on it...
This would come in handy..
thanks
..erm, that's a list box, just add one to your form (it will be called list1 by default).Quote:
Originally posted by Myrrdan
i have an error of Object variable not set on the list1.hwnd, what is list1 supposed to be?
Yet another alternative (perhaps more traditional):
Code:Private Sub Command1_Click()
Dim NameFile As String, SubDir As String
SubDir = CurDir$ & "\*.*" ' Change CurDir to whatever directory is being searched
NameFile = Dir$(SubDir)
Do While NameFile <> vbNullString
List1.AddItem NameFile
NameFile = Dir$
Loop
End Sub
You can use the FindFile and FindNextFile api's. I personally find it much better to use api's.
I've got a class somewhere's, just give me a minute to find it, and I will post it.
Basic example, and you will need to change it to fit your needs.
Thanks guy's, although I found another code :
VB Code:
Function FolderContents(ByRef thePath As String, ByRef bolRecurseDirectories As Boolean, ByRef scratchfile As String) Dim objFSO Set objFSO = CreateObject("Scripting.FileSystemObject") Dim objFolder Set objFolder = objFSO.getFolder(thePath) Call DisplayFolderContents(objFolder, bolRecurseDirectories, outFile) Set objFolder = Nothing Set objFSO = Nothing End Function Function DisplayFolderContents(objFolder, ByVal bolRecurseDirectories As Boolean, outFile) Dim objFile, strPath, strExtension For Each objFile In objFolder.Files strPath = objFile.Path If FileLen(Trim(strPath)) <> 0 Then List3.AddItem (objFile.Path) Next ' Recurse subdirectories if necessary Dim objSubFolder If bolRecurseDirectories Then For Each objSubFolder In objFolder.SubFolders DisplayFolderContents objSubFolder, bolRecurseDirectories, outFile Next End If End Function Private Sub Command1_Click() FolderContents Text1.Text, True, "" end sub
This can handle little maps, but if I'd try to use it on c:
then the program stops responding...
He said no fso, lol.
Did you try CodeDoc's suggestion in #13?