Results 1 to 2 of 2

Thread: copyfile api help.

Threaded View

  1. #2
    Fanatic Member DrUnicode's Avatar
    Join Date
    Mar 2008
    Location
    Natal, Brazil
    Posts
    631

    Re: copyfile api help.

    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
    Last edited by DrUnicode; Sep 9th, 2008 at 09:35 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width