Path has trailing "\" and "\tmp.txt" has leading "\" so that means there are 2 "\".
Use QualifyPath Function which adds a trailing "\" when necessary.
Code:Option Explicit 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 = QualifyPath("C:\") Path2 = QualifyPath("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 Public Function QualifyPath(ByVal Path As String) As String Dim Delimiter As String ' segmented path delimiter If InStr(Path, "://") > 0 Then ' it's a URL path Delimiter = "/" ' use URL path delimiter Else ' it's a disk based path Delimiter = "\" ' use disk based path delimiter End If Select Case Right$(Path, 1) ' whats last character in path? Case "/", "\" ' it's one of the valid delimiters QualifyPath = Path ' use the supplied path Case Else ' needs a trailing path delimiter QualifyPath = Path & Delimiter ' append it End Select End Function




Reply With Quote