Whats wrong with the code below?
It wont copy the file tmp.txt too the new location?Code:Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long Private Sub Form_Load() Dim Path As String Dim Path2 As String Path = "C:\" Path2 = "D:\" Dim g g = CopyFile(Path & "\tmp.txt", Path2 & "\temp.txt", True) g = CopyFile(Path & "\tmp2.txt", Path2 & "\temp2.txt", True) g = CopyFile(Path & "\tmp3.txt", Path2 & "\temp3.txt", True) g = CopyFile(Path & "\tmp4.txt", Path2 & "\temp4.txt", True) g = CopyFile(Path & "\tmp5.txt", Path2 & "\temp5.txt", True) g = CopyFile(Path & "\tmp6.txt", Path2 & "\temp5.txt", True) g = CopyFile(Path & "\tmp7.txt", Path2 & "\temp6.txt", True) End Sub
And the below code works but when i replace it with path & path2 above it doesnt work.
Whats wrong with the modified code?Code:Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long Private Sub Form_Load() 'Dim g g = CopyFile("C:\tmp.txt", "D:\tmp.txt", True) End Sub
Note: Yes i know i can use the standard filecopy method but the copyfile api copies much faster.




Reply With Quote