Public Class Form1
Dim Path As IO.DirectoryInfo
Dim DirAble As Boolean = False
Dim secondStep As Boolean = False
Private Sub BTDir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTDir.Click
Dim result = FBDMain.ShowDialog()
If result = Windows.Forms.DialogResult.Cancel Then
Exit Sub
End If
TBDir.Text = FBDMain.SelectedPath
Check()
End Sub
Sub Check()
LBMain.Items.Clear()
If IO.Directory.Exists(TBDir.Text) Then
Path = New IO.DirectoryInfo(TBDir.Text)
LBMain.Items.Add("就绪...")
DirAble = True
Else
LBMain.Items.Add("请输入路径...")
DirAble = False
End If
End Sub
Private Sub TBDir_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TBDir.KeyPress
If Asc(e.KeyChar) = 13 Then
If secondStep Then
StartTreat()
Else
If DirAble Then
' 有效并锁定
secondStep = True
LBMain.Items.Clear()
LBMain.Items.Add("已经锁定路径为:" & TBDir.Text)
LBMain.Items.Add("请输入有效的重命名字符")
TBDir.Text = ""
BTDir.Enabled = False
Else
' 锁定无效
LBMain.Items.Clear()
LBMain.Items.Add("无效路径不能锁定。")
End If
End If
End If
End Sub
Private Sub TBDir_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TBDir.TextChanged
If Not secondStep Then Check()
End Sub
Function CollectNums(ByVal From As String)
Dim num As Integer = 0
Dim c As String = ""
Dim lock As Integer = False
For i As Integer = 1 To From.Length - 1
c = From(i)
If Asc(c) >= Asc("0") And Asc(c) <= Asc("9") Then
lock = True
num = num * 10 + CInt(c)
ElseIf lock Then
Exit For
End If
Next
Return num
End Function
Sub StartTreat()
TBDir.Enabled = False
Dim a As New ArrayList
Dim s As String
LBMain.Items.Clear()
LBMain.Items.Add(Path.FullName)
For Each i As IO.FileInfo In Path.GetFiles("*.*")
If Not i.Extension = ".torrent" Then
s = TBDir.Text.Replace("%", CollectNums(i.Name)) + i.Extension
LBMain.Items.Add(s)
i.MoveTo(i.Directory.FullName + "\" + s)
End If
Next
End Sub
End Class