|
-
Jul 18th, 2000, 05:41 AM
#1
Thread Starter
Lively Member
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.
-
Jul 18th, 2000, 05:52 AM
#2
Addicted Member
Code:
Dim Dest as String
Dest = "C:\"
If Right$(Dest,1) <> "\" then
Dest = Dest & "\"
End If
Visual Basic 6 Enterprise Edition + SP4
-
Jul 18th, 2000, 05:53 AM
#3
_______
<?>
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
-
Jul 18th, 2000, 05:56 AM
#4
Addicted Member
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
-
Jul 18th, 2000, 06:11 AM
#5
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|