Как узнать имя и путь всех файлов и подпапок находящихся в папке? - VB
Формулировка задачи:
Подсажите как можно узнать имя и путь всех файлов и подпапок находящихся в папке.
Решение задачи: «Как узнать имя и путь всех файлов и подпапок находящихся в папке?»
textual
Листинг программы
Private Declare Function FindFirstFile Lib 'kernel32' Alias 'FindFirstFileA' (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long Private Declare Function FindNextFile Lib 'kernel32' Alias 'FindNextFileA' (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long Private Declare Function FindClose Lib 'kernel32' (ByVal hFindFile As Long) As Long Const MAX_PATH = 260 Const INVALID_HANDLE_VALUE = -1 Private Type FILETIME dwLowDateTime As Long dwHighDateTime As Long End Type Private Type WIN32_FIND_DATA dwFileAttributes As Long ftCreationTime As FILETIME ftLastAccessTime As FILETIME ftLastWriteTime As FILETIME nFileSizeHigh As Long nFileSizeLow As Long dwReserved0 As Long dwReserved1 As Long cFileName As String * MAX_PATH cAlternate As String * 14 End Type Function StripNulls(OriginalStr As String) As String If (InStr(OriginalStr, Chr(0)) > 0) Then OriginalStr = Left(OriginalStr, InStr(OriginalStr, Chr(0)) - 1) End If StripNulls = OriginalStr End Function Sub EnumFilesAPI(ByVal path As String, ByVal SearchStr As String) Dim FileName As String Dim hSearch As Long Dim WFD As WIN32_FIND_DATA Dim Cont As Integer If Right(path, 1) <> ' ' Then path = path & ' ' hSearch = FindFirstFile(path & SearchStr, WFD) Cont = True If hSearch <> INVALID_HANDLE_VALUE Then While Cont FileName = StripNulls(WFD.cFileName) If (FileName <> '.') And (FileName <> '..') Then List1.AddItem path & FileName End If Cont = FindNextFile(hSearch, WFD) Wend FindClose hSearch End If End Sub Sub Command1_Click() Dim SearchPath As String, FindStr As String Dim FileSize As Long Dim NumFiles As Integer, NumDirs As Integer Screen.MousePointer = vbHourglass List1.Clear SearchPath = Text1.Text FindStr = Text2.Text EnumFilesAPI SearchPath, FindStr Screen.MousePointer = vbDefault End Sub
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д