今天查了查msdn,做了个简单的批量文件更名的程序!

呵呵,有意思!
Imports System.IO
Namespace Xyn.Xyn
Public Class MainBase
Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

Public Sub New()
MyBase.New()

'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()

'在 InitializeComponent() 调用之后添加任何初始化

End Sub

'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer

'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents MyFolderBrowserDialog As System.Windows.Forms.FolderBrowserDialog
Friend WithEvents MyButton As System.Windows.Forms.Button
Friend WithEvents MyTextBox As System.Windows.Forms.TextBox
Friend WithEvents PathBox As System.Windows.Forms.TextBox
Friend WithEvents Submit As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label

  1<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()   
  2Me.MyFolderBrowserDialog = New System.Windows.Forms.FolderBrowserDialog   
  3Me.MyButton = New System.Windows.Forms.Button   
  4Me.MyTextBox = New System.Windows.Forms.TextBox   
  5Me.PathBox = New System.Windows.Forms.TextBox   
  6Me.Submit = New System.Windows.Forms.Button   
  7Me.Label1 = New System.Windows.Forms.Label   
  8Me.Label2 = New System.Windows.Forms.Label   
  9Me.SuspendLayout()   
 10'   
 11'MyButton   
 12'   
 13Me.MyButton.Location = New System.Drawing.Point(257, 57)   
 14Me.MyButton.Name = "MyButton"   
 15Me.MyButton.Size = New System.Drawing.Size(104, 21)   
 16Me.MyButton.TabIndex = 0   
 17Me.MyButton.Text = "选择"   
 18'   
 19'MyTextBox   
 20'   
 21Me.MyTextBox.Location = New System.Drawing.Point(119, 112)   
 22Me.MyTextBox.Name = "MyTextBox"   
 23Me.MyTextBox.Size = New System.Drawing.Size(104, 21)   
 24Me.MyTextBox.TabIndex = 1   
 25Me.MyTextBox.Text = ""   
 26'   
 27'PathBox   
 28'   
 29Me.PathBox.Location = New System.Drawing.Point(121, 57)   
 30Me.PathBox.Name = "PathBox"   
 31Me.PathBox.ReadOnly = True   
 32Me.PathBox.Size = New System.Drawing.Size(104, 21)   
 33Me.PathBox.TabIndex = 2   
 34Me.PathBox.Text = ""   
 35'   
 36'Submit   
 37'   
 38Me.Submit.Location = New System.Drawing.Point(255, 111)   
 39Me.Submit.Name = "Submit"   
 40Me.Submit.Size = New System.Drawing.Size(104, 21)   
 41Me.Submit.TabIndex = 3   
 42Me.Submit.Text = "确定"   
 43'   
 44'Label1   
 45'   
 46Me.Label1.Location = New System.Drawing.Point(33, 57)   
 47Me.Label1.Name = "Label1"   
 48Me.Label1.Size = New System.Drawing.Size(64, 18)   
 49Me.Label1.TabIndex = 4   
 50Me.Label1.Text = "选择路径"   
 51Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight   
 52'   
 53'Label2   
 54'   
 55Me.Label2.Location = New System.Drawing.Point(31, 111)   
 56Me.Label2.Name = "Label2"   
 57Me.Label2.Size = New System.Drawing.Size(72, 18)   
 58Me.Label2.TabIndex = 5   
 59Me.Label2.Text = "起始文件名"   
 60Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight   
 61'   
 62'MainBase   
 63'   
 64Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)   
 65Me.ClientSize = New System.Drawing.Size(392, 190)   
 66Me.Controls.Add(Me.Label2)   
 67Me.Controls.Add(Me.Label1)   
 68Me.Controls.Add(Me.Submit)   
 69Me.Controls.Add(Me.PathBox)   
 70Me.Controls.Add(Me.MyTextBox)   
 71Me.Controls.Add(Me.MyButton)   
 72Me.Name = "MainBase"   
 73Me.Text = "批量文件命名"   
 74Me.ResumeLayout(False) 
 75
 76End Sub 
 77
 78#End Region   
 79Private Sub MyButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyButton.Click   
 80Try   
 81MyFolderBrowserDialog = New FolderBrowserDialog   
 82MyFolderBrowserDialog.ShowDialog()   
 83PathBox.Text = MyFolderBrowserDialog.SelectedPath   
 84Catch ex As Exception   
 85End Try   
 86End Sub 
 87
 88Private Sub Submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Submit.Click   
 89Dim MyMessageBox As New MsgBoxResult   
 90MyMessageBox = MsgBox("确定要重命名么?", MsgBoxStyle.OKCancel, "真的么?")   
 91If MyMessageBox = MsgBoxResult.Cancel Then   
 92Return   
 93End If   
 94Try   
 95Dim mystrings As String() = Directory.GetFiles(PathBox.Text)   
 96Dim mystring As String   
 97Dim i As Integer = 0   
 98For Each mystring In mystrings   
 99Rename(mystring, mystring.Substring(0, Len(PathBox.Text) + 1) + MyTextBox.Text + i.ToString + mystring.Substring(Len(mystring) - 4))   
100i = i + 1   
101Next   
102PathBox.Text = ""   
103MyTextBox.Text = ""   
104Catch ex As Exception   
105End Try   
106End Sub   
107End Class   
108End Namespace</system.diagnostics.debuggerstepthrough()>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus