Reputation: 921
I want to transfer files from one directory to another using streamreader and writer class. Now i want to add a statusbar to show the filename on statusbar along with the remaining percentage. It will reach 100 when file has been moved to new directory. Any suggestions please?
Dim ioFile As New System.IO.StreamReader("C:\sample.csv")
Dim ioLine As String
Dim ioLines As String
ioLine = ioFile.ReadLine
ioLines = ioLine
While Not ioLine = ""
ioLine = ioFile.ReadLine
ioLines = ioLines & vbCrLf & ioLine
End While
Dim ioWriter As New System.IO.StreamWriter("C:\new.csv")
ioWriter.WriteLine(ioLines)
ioFile.Close()
ioWriter.Close()
Upvotes: 1
Views: 7638
Reputation: 81610
Saif Kahn is right, if you are just copying a file, then just copy a file. But to answer your question, here is a progress bar:
Dim tmpLines() as String = File.ReadAllLines("c:\sample.csv")
ProgressBar1.Maximum = tmpLines.Count - 1
ProgressBar1.Value = 0
For tmpRun As Integer = 0 To tmpLines.Count - 1
ProgressBar1.Value += 1
'Copy Stuff
Next
Upvotes: 1
Reputation: 18772
Try this
' Copy the file to a new folder, overwriting existing file.
My.Computer.FileSystem.CopyFile( _
"C:\UserFiles\TestFiles\testFile.txt", _
"C:\UserFiles\TestFiles2\testFile.txt", _
FileIO.UIOption.AllDialogs, _
FileIO.UICancelOption.DoNothing)
The My.Computer.FileSystem.CopyFile method allows you to copy files. Its parameters provide the ability to overwrite existing files, rename the file, show the progress of the operation, and allow the user to cancel the operation
Upvotes: 1