making a backup file

superstud101

Member
Joined
May 27, 2008
Messages
7
Programming Experience
Beginner
hi sorry if this sound daft but i wont to make a backup of a file in to the same
folder as the original but with ".BAK" added to the end.

VB.NET:
If CheckBox1.Checked = True
            
put needed code here

        Else
            Return
        End If

thanx in advance for any help you can give
 
VB.NET:
Dim filepath As String = "c:\some\file.jpg"
IO.File.Copy(filepath, IO.Path.ChangeExtension(filepath, ".bak"))
 
VB.NET:
Dim filepath As String = "c:\some\file.jpg"
IO.File.Copy(filepath, IO.Path.ChangeExtension(filepath, ".bak"))

thanx for the quick reply but works great but i wont to add .bak to the file so it would be like this

text.txt
to
text.txt.bak

sorry i should of been more clearer

thanx for your help
 
Add two strings together with the & operator. "hello" & "world"
 
hi i have this code but i get an error

Conversion from string "??" to type 'Long' is not valid.

VB.NET:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim Filename As String
        Dim fs_con As System.IO.FileStream
        Dim CONHeader(CON_HEADER_LEN - 1) As Byte
        Dim fullPath As String
        Dim dirName As String
        Dim Backup As String = ".bak"
        
        If CheckBox1.Checked = True

            fullPath = Label4.Text
            dirName = Label5.Text
            Filename = IO.Path.GetFileName(fullPath)

            My.Computer.FileSystem.CopyFile(fullPath, dirName \ Filename & Backup, True)

        Else
            Return
        End If
 
My.Computer.FileSystem.CopyFile(fullPath, dirName \ Filename & Backup, True)

You can't divide strings.

Looks like you want something like:

My.Computer.FileSystem.CopyFile(fullPath, dirName & "\" & Filename & Backup, True)

That is, of course, assuming dirName and Filename are both variables you have defined.
 
Back
Top