Buffer file

  • Thread starter Thread starter mipakteh
  • Start date Start date
M

mipakteh

Guest
Hi All,

What trying to do is;

1.Save all file in c:\windows\system32 to the buffer c:\my Documents\Backup_32

2.When computer detect one of the file in c:\windows\system32 has changed then restore back from Buffer.

Thank.

Imports System.IO
Imports System.Text
Imports System.Diagnostics

Public Class Form1
Dim watchfolder As New FileSystemWatcher

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

watchfolder.Path = "c:\windows\system32"

AddHandler watchfolder.Deleted, Sub()
MsgBox("File Delete")
End Sub
AddHandler watchfolder.Renamed, Sub()
MsgBox("File Rename")
End Sub
AddHandler watchfolder.Changed, Sub()
MsgBox("File Changed")
End Sub
AddHandler watchfolder.Created, Sub()
MsgBox("File Created")
End Sub


watchfolder.EnableRaisingEvents = True

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

Dim sFolder As String = "c:\windows\system32"
Dim sFolder_Copy As String = "C:\Users\Uset\Documents\Backup_Sys32"

For Each foundFile As String In My.Computer.FileSystem.GetFiles(sFolder)
TextBox1.AppendText(foundFile & vbCrLf)

' convert string to stream
Dim buffer As Byte() = Encoding.ASCII.GetBytes(foundFile)
Dim ms As New MemoryStream(buffer)
'write to file
Dim file As New FileStream(sFolder_Copy, FileMode.Create, FileAccess.Write)
ms.WriteTo(file)

file.Close()
ms.Close()

Next

End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

Dim sFolder_Copy As String = "C:\Users\Uset\Documents\Backup_Sys32"
Dim Text As String = ""

Dim f As System.IO.FileStream
Dim i As Integer
Dim mybuffer(100) As Byte
f = New System.IO.FileStream(sFolder_Copy, IO.FileMode.Open, IO.FileAccess.Read)
f.Read(mybuffer, 0, 100)
For i = 0 To 100
Text &= Chr(mybuffer(i))
'Need to see in progress
'TextBox2.AppendText(? & vbCrLf)
Next
f.Close()



End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click

End Sub
End Class

Continue reading...
 
Back
Top