haw_4er > 09-09-13, 03:25 PM
Xuân Thanh > 09-09-13, 11:04 PM
(09-09-13, 03:25 PM)haw_4er Đã viết: Chào cả nhà,
Mình có 1 vấn đề này, mong cả nhà giúp mình
Như trên tiêu đề, mình muốn list box hiện tên cá file có trong 1 folder bất kỳ.
Cám ơn cả nhà nhiều ^^
haw_4er > 10-09-13, 12:16 PM
Xuân Thanh > 10-09-13, 01:09 PM
Sub GetFile()
Dim i As Long, MyDir As String
MyDir = "D:\Access"
With Application.FileSearch
.LookIn = MyDir '<--- Tim trong thu muc này
.FileName = "*.*" '<--- Kieu file can tìm
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
Me.lstTenFile.AddItem Replace(.FoundFiles(i), MyDir & "\", "") '<--- Chi lay ten file
Me.lstDuongDan.AddItem .FoundFiles(i) '<----Lay ca duong dan
Next i
End If
End With
End Sub
MTNQ > 21-10-13, 12:45 AM
Xuân Thanh > 21-10-13, 12:19 PM
Function GetListFile(ByVal Folder As String, ByVal Search As String, ByVal InSub As Boolean)
Dim sComm As String, tmpFile
On Error GoTo ExitSub
If Right(Folder, 1) <> "\" Then Folder = Folder & "\"
Folder = """" & Folder & """"
With CreateObject("Scripting.FileSystemObject")
tmpFile = .GetTempName
sComm = "DIR " & Folder & "*" & Search & "* /ON /B /A-D " & IIf(InSub, "/S", " ") & " >" & tmpFile
CreateObject("Wscript.Shell").Run "cmd /c " & sComm, 0, True
GetListFile = Split(.OpenTextFile(tmpFile, 1).ReadAll, vbCrLf)
End With
Kill tmpFile
ExitSub:
End Function