Problemer med FindFileFirst og Next
Er der en der kan gennemskue hvad der er galt med følgende kodeImports System.Runtime.InteropServices
Public Class PCopy
Public Const MAX_PATH As Long = 260
Private Const ERROR_NO_MORE_FILES As Long = 18&
Private Const INVALID_HANDLE_VALUE As Short = -1
Private Const FILE_ATTRIBUTE_ARCHIVE As Short = &H20
Private Const FILE_ATTRIBUTE_DIRECTORY As Short = &H10
Private Const FILE_ATTRIBUTE_HIDDEN As Short = &H2
Private Const FILE_ATTRIBUTE_NORMAL As Short = &H80
Private Const FILE_ATTRIBUTE_READONLY As Short = &H1
Private Const FILE_ATTRIBUTE_SYSTEM As Short = &H4
Private Const FILE_ATTRIBUTE_TEMPORARY As Short = &H100
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
<DllImport("kernel32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function CopyFile(ByVal src As String, ByVal dst As String, ByVal failIfExists As Boolean) As Boolean
End Function
<DllImport("kernel32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function FindFirstFile(ByVal lpFileName As String, ByRef lpFindFileData As WIN32_FIND_DATA) As IntPtr
End Function
<DllImport("kernel32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function FindNextFile(ByVal hFindFile As IntPtr, ByRef lpFindFileData As WIN32_FIND_DATA) As Boolean
End Function
<DllImport("kernel32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function FindClose(ByVal hFindFile As Long) As Long
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub StartCopy_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartCopy_Button.Click
CopyDirectory("c:\Test\", "f:\test\", False)
End Sub
Sub CopyDirectory(ByVal SourcePath As String, ByVal DestPath As String, Optional ByVal Overwrite As Boolean = False)
Dim fData As New WIN32_FIND_DATA
Dim fHandel As IntPtr
Dim fTime As FILETIME
fHandel = FindFirstFile(SourcePath & "*.*", fData)
Debug.Print (fData.cfilename)
If fHandel <> INVALID_HANDLE_VALUE Then
While FindNextFile(fHandel, fData) <> 0
Debug.Print (fData.cfilename)
fTime = fData.ftLastWriteTime
End While
FindClose(fHandel)
Else
Debug.Print("INVALID_HANDLE_VALUE")
End If
End Sub
End Class
Det eneste der fremkommer når jeg udskriver fData.cFilename er tomme linier og x.
Bruger VB 2008 Express og køre windows 7