Private Sub DisplayUsage()
Dim originalForegroundColor As ConsoleColor = Console.ForegroundColor
Console.Clear()
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine("DirCopy 1.0")
Console.WriteLine("Written by Josh Fitzgerald")
Console.WriteLine(New String("-", Console.WindowWidth))
Console.WriteLine("DirCopy will copy all of the files from the
source folder to the")
Console.WriteLine("destination folder. While the files are
copying, a progress bar")
Console.WriteLine("will display the percent complete.")
Console.WriteLine()
Console.WriteLine("If a directory name contains spaces, enclose
it in double quotes.")
Console.WriteLine()
Console.Write("Example : ")
Console.ForegroundColor = ConsoleColor.Magenta
Console.WriteLine("DirCopy C:"MyFolder C:"MyNewFolder")
Console.ForegroundColor = ConsoleColor.Green
Console.WriteLine()
Console.Write("Example : ")
Console.ForegroundColor = ConsoleColor.Magenta
Console.WriteLine("DirCopy ""C:"My Folder"" ""C:"My New Folder""")
Console.ForegroundColor = originalForegroundColor
End Sub
Private Sub CopyFiles(ByVal srcDir As String, ByVal destDir As String)
Const BufferSourceTopLine As Integer = 8
Const BufferDestinationTopLine As Integer = 7
Dim rowIndex As Integer = 7
Dim originalForegroundColor As ConsoleColor = Console.ForegroundColor
Console.CursorVisible = False
Console.Clear()
Dim numberOfFiles As Integer
numberOfFiles = My.Computer.FileSystem.GetFiles(srcDir).Count
Dim PB As New ConsoleProgressBar(numberOfFiles)
DisplayHeader(srcDir, destDir)
Dim fileCounter As Integer = 1
For Each f As String In My.Computer.FileSystem.GetFiles(srcDir)
Dim fi As New System.IO.FileInfo(f)
Console.ForegroundColor = ConsoleColor.Green
Console.SetCursorPosition(0, rowIndex)
Console.Write(fi.Name)
If rowIndex < Console.WindowHeight - 1 Then
rowIndex += 1
Else
Console.MoveBufferArea(0,BufferSourceTopLine, _
Console.WindowWidth, _
Console.WindowHeight - _
BufferSourceTopLine, _
0, _
BufferDestinationTopLine)
End If
My.Computer.FileSystem.CopyFile(fi.FullName, destDir &""" & fi.Name)
pb.Update( fileCounter)
fileCounter += 1
Next
Console.ForegroundColor = originalForegroundColor
Console.SetCursorPosition(0, Console.WindowHeight - 1)
Console.CursorVisible = True
End Sub
Console.MoveBufferArea(0, _
BufferSourceTopLine, _
Console.WindowWidth, _
Console.WindowHeight - BufferSourceTopLine, _
0, _
BufferDestinationTopLine)
Public Sub New(ByVal MaximumValue As Long)
m_length = Console.WindowWidth - 10
m_left = 7
m_right = m_left + m_length + 1
m_progressBarRow = 1
m_messageBarRow = m_progressBarRow + 1
m_percentPosition = 4
m_maximumValue = MaximumValue
m_currentValue = 0
Initialize()
End Sub
Public Sub Update(ByVal CurrentValue As Long)
m_currentValue = CurrentValue
m_currentBarLength = CInt((m_currentValue / m_maximumValue) * m_length)
Refresh()
End Sub
Private Sub UpdateProgressBar()
Dim originalForegroundColor As ConsoleColor = Console.ForegroundColor
Dim originalBackgroundColor As ConsoleColor = Console .BackgroundColor
Console.ForegroundColor = ConsoleColor.Black
Console.BackgroundColor = ConsoleColor.Green
Console.SetCursorPosition(m_left + 1 m_progressBarRow)
Dim progress As New String("O", m_currentBarLength)
Console.Write(progress)
Console.ForegroundColor =originalForegroundColor
Console.BackgroundColor = originalBackgroundColor
End Sub
用勤奋之这石,补能力之缺口!