Advertisement
Advertisement
| 09.03.2008 at 11:14AM PDT, ID: 23700240 | Points: 500 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: |
Public Class Form1
Private Structure FILETIME
Dim dwLowDateTime As Long
Dim dwHighDateTime As Long
End Structure
Private Structure WIN32_FIND_DATA
Dim dwFileAttributes As Integer
Dim ftCreationTime As FILETIME
Dim ftLastAccessTime As FILETIME
Dim ftLastWriteTime As FILETIME
Dim nFileSizeHigh As Integer
Dim nFileSizeLow As Integer
Dim dwReserved0 As Integer
Dim dwReserved1 As Integer
<VBFixedString(MAX_PATH), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=MAX_PATH)> Dim cFileName As String
<VBFixedString(14), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst:=14)> Dim cAlternate As String
End Structure
Private Const MAX_PATH As Short = 260
Private Const INVALID_HANDLE_VALUE As Short = -1
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, ByVal lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, ByVal lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Function TrimNull(ByVal sFileName As String) As String
Dim i As Long
' Search for the first null character
i = InStr(1, sFileName, vbNullChar)
If i = 0 Then
TrimNull = sFileName
Else
'Return the file name
TrimNull = tLeft(sFileName, i - 1)
End If
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Buffer for output result
Dim sBuff As String
' File search handle
Dim iSearchHandle As Long
' File search buffer
Dim pFindFileBuff As WIN32_FIND_DATA
sBuff = vbNullString
' Find first file and create search handle
iSearchHandle = FindFirstFile("C:\temp\*.*", pFindFileBuff)
' Check if FindFirstFile call was successful
If iSearchHandle <> INVALID_HANDLE_VALUE Then
' Store first file name and date in the buffer
sBuff = TrimNull(pFindFileBuff.cFileName)
' Find the rest of files with the FindNextFile function
Do While FindNextFile(iSearchHandle, pFindFileBuff)
sBuff = sBuff & TrimNull(pFindFileBuff.cFileName)
Loop
' Close file search handle
Call FindClose(iSearchHandle)
End If
' Show results
MsgBox(sBuff)
End Sub
Public Function tLeft(ByVal sText As String, ByVal nLen As Integer) As String
If nLen > sText.Length Then nLen = sText.Length
Return (sText.Substring(0, nLen))
End Function
End Class
|