Results 1 to 5 of 5

Thread: getting the directory to a file correct?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 1999
    Location
    Brisbane, Qld, Australia
    Posts
    78

    Question

    Hi,

    I am using the showfolder method to get a location to a directory. I have this working and now I want to add a filename to that directory. I have the problem of the dir and filename joining together as one long filename or nothing happening. The problem : \ .

    The code:

    Private Sub CmdOk_Click() 'the ok button to start the process

    Dim SFile As String
    Dim Dest As String
    Dim x As String
    Dim Ans As String

    CmdCancel.Enabled = False
    CmdBrowse.Enabled = False
    CmdOK.Enabled = False

    SFile = App.path & "\Client.mdb"
    Dest = TxtDest.Text
    x = CopyDB(SFile, Dest)
    Unload FrmBackup
    Ans = MsgBox("Backup Complete!", vbInformation)

    End Sub

    Private Function CopyDB(SFile As String, Dest As String) As Long

    Dim WFD As WIN32_FIND_DATA
    Dim SA As SECURITY_ATTRIBUTES
    Dim hFile As Long
    Dim currFile As String

    Call CreateDirectory(Dest, SA)
    hFile = FindFirstFile(SFile, WFD)
    If (hFile = INVALID_HANDLE_VALUE) Then
    MsgBox "An error has occured locating the Database to Backup. Please retry."
    Exit Function

    End If

    If hFile Then
    currFile = Left$(WFD.cFileName, InStr(WFD.cFileName, Chr$(0)))

    Call CopyFile(SFile, Dest & currFile, False)

    End If
    Call FindClose(hFile)
    End Function

    If i add a \ to the line like this :
    Call CopyFile(SFile, Dest & "\" & Currfile, false)

    then it will add an extra \ if you use d:\ ie d:\\

    If I add it to the Dest like this:
    Dest = TxtDest.Text & "\"

    same thing happens. Is there a way to have vb tell it when it needs a \? Any help would be great and thanx in advance.

  2. #2
    Addicted Member
    Join Date
    Apr 2000
    Location
    Sheffield, England.
    Posts
    136
    Code:
    Dim Dest as String
    
    Dest = "C:\"
    
    If Right$(Dest,1) <> "\" then
        Dest = Dest & "\"
    End If
    Visual Basic 6 Enterprise Edition + SP4

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'use the Right String function
    
    if Right(Dest,1) <> "\" then
          Dest = Dest & "\"
       else
    endif
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    Addicted Member
    Join Date
    Jul 2000
    Location
    Scotland
    Posts
    184
    Perhaps this might help.

    Sub TestIt(Dest As String)

    If (Right$(Dest, 1) = "\") Then
    'dont add it
    MsgBox Dest
    Else
    'add it
    MsgBox Dest & "\"
    End If
    End Sub

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jun 1999
    Location
    Brisbane, Qld, Australia
    Posts
    78

    Thumbs up

    Thanks guys and gals. That works great. So simple but so effective.

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