Results 1 to 6 of 6

Thread: [resolved] Problem with FTP Rename

Threaded View

  1. #1

    Thread Starter
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Resolved [resolved] Problem with FTP Rename

    My Declarations
    Code:
    Public Declare Function apiFtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" (ByVal hConnect As Long, ByVal lpszExisting As String, ByVal lpszNew As String) As Boolean
    Public Declare Function apiFtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" (ByVal hConnect As Long, ByVal lpszFileName As String) As Boolean
    Public Declare Function apiFtpCreateDirectory Lib "wininet.dll" Alias "FtpCreateDirectoryA" (ByVal hConnect As Long, ByVal lpszDirectory As String) As Boolean
    Public Declare Function apiFtpRemoveDirectory Lib "wininet.dll" Alias "FtpRemoveDirectoryA" (ByVal hConnect As Long, ByVal lpszDirectory As String) As Boolean
    and my rename code
    Code:
    Public Function RenameFile(ByVal strOldName As String, ByVal strNewName As String, ByVal blnFtpFile As Boolean) As Boolean
        
    '---- FTP -
    '----   will work on the current directory (make sure you are there before calling)
        
    '---- Local -
    '----   Use fill file path names
        
    '----   Note: To rename a directory, use this function
        
        Dim lngRes As Long
        
        On Error Resume Next
        
        RenameFile = True
        
        If blnFtpFile Then
            If IntCon.zIntConHandle <> 0 Then
                lngRes = apiFtpRenameFile(IntCon.zIntConHandle, ByVal strOldName, ByVal strNewName)
            End If
        Else
    '---- local drive rename
    '        lngRes = apiMoveFile(strOldName, strNewName) 'only api to rename a local file
        End If
        
    '---- repeated error msg/clean up
        If Err.Number <> 0 Then
            RenameFile = False
            MsgBox "Error : " & Err.Number & vbCrLf & Err.Description, vbOKOnly + vbExclamation, "Error"
            Err.Clear
        End If
        
        
        If Err.LastDllError <> 0 Then
            RenameFile = False
            MsgBox "Last DLL Error : " & Err.LastDllError, vbOKOnly + vbExclamation, "Error Last Error"
            Err.Clear
        End If
    End Function
    Now it works fine but still raises an error (lastdll) of 2 - which I think is that it cannot find the file.

    I am tempted to ignore that error as it is working, but I wanted to make sure.
    I looked on google, but MSDN says it`s a function, and ActiveVB says its a sub. Confused? I am!

    The function sounds better (at least you'd know if it worked of not).
    Comments?
    Last edited by Ecniv; May 17th, 2005 at 02:52 AM.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

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