VB.NET批量重命名修改大揭秘

学习VB.NET编程的都知道重命名的问题,随着我在工作中的积累,对VB.NET批量重命名的代码编辑上做了一些总结,下面给大家列举一个VB.NET批量重命名代码实例,希望可以给大家带来帮助。

创新互联长期为近1000家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为宁城企业提供专业的成都网站设计、做网站,宁城网站改版等技术服务。拥有十载丰富建站经验和众多成功案例,为您定制开发。

 
 
 
  1. Imports System.IO  
  2. Public Class Form1  
  3. Inherits System.Windows.Forms.Form  
  4. #Region " Windows 窗体设计器生成的代码 "  
  5. Public Sub New()  
  6. MyBase.New()  
  7. '该调用是 Windows 窗体设计器所必需的。  
  8. InitializeComponent()  
  9. '在 InitializeComponent() 调用之后添加任何初始化  
  10. End Sub  
  11. '窗体重写 dispose 以清理组件列表。  
  12. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)  
  13. If disposing Then  
  14. If Not (components Is Nothing) Then  
  15. components.Dispose()  
  16. End If  
  17. End If  
  18. MyBase.Dispose(disposing)  
  19. End Sub  
  20. 'Windows 窗体设计器所必需的  
  21. Private components As System.ComponentModel.IContainer  
  22. '注意: 以下过程是 Windows 窗体设计器所必需的  
  23. '可以使用 Windows 窗体设计器修改此过程。  
  24. '不要使用代码编辑器修改它。  
  25. Friend WithEvents Button1 As System.Windows.Forms.Button  
  26. Friend WithEvents TextBox1 As System.Windows.Forms.TextBox  
  27. Friend WithEvents Button2 As System.Windows.Forms.Button  
  28. Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox  
  29. Friend WithEvents TextBox2 As System.Windows.Forms.TextBox  
  30. Friend WithEvents Button3 As System.Windows.Forms.Button  
  31. Friend WithEvents Label1 As System.Windows.Forms.Label  
  32. Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar  
  33. Friend WithEvents Label2 As System.Windows.Forms.Label  
  34. Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox  
  35. Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu  
  36. Friend WithEvents LinkLabel1 As System.Windows.Forms.LinkLabel  
  37. ()> Private Sub InitializeComponent()  
  38. Me.Button1 = New System.Windows.Forms.Button  
  39. Me.TextBox1 = New System.Windows.Forms.TextBox  
  40. Me.Button2 = New System.Windows.Forms.Button  
  41. Me.ComboBox1 = New System.Windows.Forms.ComboBox  
  42. Me.TextBox2 = New System.Windows.Forms.TextBox  
  43. Me.Button3 = New System.Windows.Forms.Button  
  44. Me.Label1 = New System.Windows.Forms.Label  
  45. Me.ProgressBar1 = New System.Windows.Forms.ProgressBar  
  46. Me.Label2 = New System.Windows.Forms.Label  
  47. Me.CheckBox1 = New System.Windows.Forms.CheckBox  
  48. Me.MainMenu1 = New System.Windows.Forms.MainMenu  
  49. Me.LinkLabel1 = New System.Windows.Forms.LinkLabel  
  50. Me.SuspendLayout()  
  51. '  
  52. 'Button1  
  53. '  
  54. Me.Button1.Location = New System.Drawing.Point(288, 120)  
  55. Me.Button1.Name = "Button1" 
  56. Me.Button1.Size = New System.Drawing.Size(112, 32)  
  57. Me.Button1.TabIndex = 0 
  58. Me.Button1.Text = "执行" 
  59. '  
  60. 'TextBox1  
  61. '  
  62. Me.TextBox1.Location = New System.Drawing.Point(32, 40)  
  63. Me.TextBox1.Name = "TextBox1" 
  64. Me.TextBox1.Size = New System.Drawing.Size(272, 21)  
  65. Me.TextBox1.TabIndex = 1  
  66. Me.TextBox1.Text = "TextBox1" 
  67. '  
  68. 'Button2  
  69. '  
  70. Me.Button2.Location = New System.Drawing.Point(336, 40)  
  71. Me.Button2.Name = "Button2" 
  72. Me.Button2.Size = New System.Drawing.Size(104, 23)  
  73. Me.Button2.TabIndex = 2  
  74. Me.Button2.Text = "目标文件夹..." 
  75. '  
  76. 'ComboBox1  
  77. '  
  78. Me.ComboBox1.Location = New System.Drawing.Point(168, 88)  
  79. Me.ComboBox1.Name = "ComboBox1" 
  80. Me.ComboBox1.Size = New System.Drawing.Size(80, 20)  
  81. Me.ComboBox1.TabIndex = 3 
  82. Me.ComboBox1.Text = "ComboBox1" 
  83. '  
  84. 'TextBox2  
  85. '  
  86. Me.TextBox2.Location = New System.Drawing.Point(168, 128)  
  87. Me.TextBox2.Name = "TextBox2" 
  88. Me.TextBox2.Size = New System.Drawing.Size(80, 21)  
  89. Me.TextBox2.TabIndex = 4 
  90. Me.TextBox2.Text = "" 
  91. '  
  92. 'Button3  
  93. '  
  94. Me.Button3.Location = New System.Drawing.Point(40, 128)  
  95. Me.Button3.Name = "Button3" 
  96. Me.Button3.Size = New System.Drawing.Size(80, 23)  
  97. Me.Button3.TabIndex = 5 
  98. Me.Button3.Text = "新增文件类型" 
  99. '  
  100. 'Label1  
  101. '  
  102. Me.Label1.Location = New System.Drawing.Point(40, 88)  
  103. Me.Label1.Name = "Label1" 
  104. Me.Label1.Size = New System.Drawing.Size(104, 23)  
  105. Me.Label1.TabIndex = 6 
  106. Me.Label1.Text = "要操作的文件类型" 
  107. '  
  108. 'ProgressBar1  
  109. '  
  110. Me.ProgressBar1.Location = New System.Drawing.Point(40, 168)  
  111. Me.ProgressBar1.Name = "ProgressBar1" 
  112. Me.ProgressBar1.Size = New System.Drawing.Size(352, 16)  
  113. Me.ProgressBar1.TabIndex = 7 
  114. '  
  115. 'Label2  
  116. '  
  117. Me.Label2.Location = New System.Drawing.Point(32, 192)  
  118. Me.Label2.Name = "Label2" 
  119. Me.Label2.Size = New System.Drawing.Size(240, 24)  
  120. Me.Label2.TabIndex = 8 
  121. Me.Label2.Text = "状态" 
  122. '  
  123. 'CheckBox1  
  124. '  
  125. Me.CheckBox1.Location = New System.Drawing.Point(304, 80)  
  126. Me.CheckBox1.Name = "CheckBox1" 
  127. Me.CheckBox1.Size = New System.Drawing.Size(136, 24)  
  128. Me.CheckBox1.TabIndex = 9 
  129. Me.CheckBox1.Text = "完成后打开文件夹" 
  130. '  
  131. 'LinkLabel1  
  132. '  
  133. Me.LinkLabel1.Location = New System.Drawing.Point(296, 200)  
  134. Me.LinkLabel1.Name = "LinkLabel1" 
  135. Me.LinkLabel1.Size = New System.Drawing.Size(144, 23)  
  136. Me.LinkLabel1.TabIndex = 10 
  137. Me.LinkLabel1.TabStop = True 
  138. Me.LinkLabel1.Text = "http://www.wgscd.com" 
  139. '  
  140. 'Form1  
  141. '  
  142. Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)  
  143. Me.ClientSize = New System.Drawing.Size(464, 238)  
  144. Me.Controls.Add(Me.LinkLabel1)  
  145. Me.Controls.Add(Me.CheckBox1)  
  146. Me.Controls.Add(Me.Label2)  
  147. Me.Controls.Add(Me.ProgressBar1)  
  148. Me.Controls.Add(Me.Label1)  
  149. Me.Controls.Add(Me.Button3)  
  150. Me.Controls.Add(Me.TextBox2)  
  151. Me.Controls.Add(Me.ComboBox1)  
  152. Me.Controls.Add(Me.Button2)  
  153. Me.Controls.Add(Me.TextBox1)  
  154. Me.Controls.Add(Me.Button1)  
  155. MeMe.Menu = Me.MainMenu1  
  156. Me.Name = "Form1" 
  157. Me.Text = "批量重命名 wgscd 2005" 
  158. Me.ResumeLayout(False)  
  159. End Sub  
  160. #End Region  
  161. Dim Path As String = "" 
  162. Dim Filter As String = "*.*" 
  163. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click  
  164. Filter = Me.ComboBox1.SelectedItem  
  165. Dim dir As DirectoryInfo  
  166. Path = Me.TextBox1.Text  
  167. If Path <> "" AndAlso Me.ComboBox1.Text <> "" Then  
  168. ' If Me.TextBox1.Text.Trim.Length > 6 Then  
  169. '  MsgBox("文件类型错误")  
  170. '  Exit Sub  
  171. '  End If  
  172. Dim D As New DirectoryInfo("Temp")  
  173. If D.Exists = False Then  
  174. D.Create()  
  175. End If  
  176. dir = New DirectoryInfo(Me.TextBox1.Text)  
  177. Dim lenth As Integer = dir.GetFiles(Filter).Length  
  178. If lenth > 0 Then  
  179. Me.ProgressBar1.Value = 0 
  180. Me.ProgressBar1.Maximum = lenth + 1  
  181. Me.Label2.Text = "正在复制到临时目录。。。" 
  182. Dim fi As FileInfo  
  183. Dim i As Integer = 1 
  184. For Each fi In dir.GetFiles(Filter)  
  185. Dim Temp As String = fi.Name  
  186. Dim Extention As String = fi.Extension  
  187. fi.CopyTo("Temp\" & i & Extention, True)  
  188. fi.Delete()  
  189. i += 1  
  190. Me.ProgressBar1.Value = i 
  191. Next  
  192. Me.ProgressBar1.Value = 0 
  193. Me.Label2.Text = "复制到临时目录完成" 
  194. Me.Label2.Text = "正在删除临时文件。。。" 
  195. dir = New DirectoryInfo("Temp")  
  196. If dir.GetFiles(Filter).Length Then  
  197. Dim fi2 As FileInfo  
  198. Dim j As Integer = 1 
  199. For Each fi2 In dir.GetFiles(Filter)  
  200. Dim Temp As String = fi2.Name  
  201. Dim Extention As String = fi2.Extension  
  202. fi2.CopyTo(Path & "\" & j & Extention, True)  
  203. fi2.Delete()  
  204. j += 1  
  205. Me.ProgressBar1.Value = j 
  206. Next  
  207. Me.Label2.Text = "处理完成" 
  208. If Me.CheckBox1.Checked Then  
  209. Dim p As New Process  
  210. p.Start(Path)  
  211. End If  
  212. End If  
  213. Else : Exit Sub  
  214. End If  
  215. Else  
  216. MsgBox("请选择设置操作路径和要文件类型")  
  217. End If  
  218. End Sub  
  219. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load  
  220. Me.TextBox1.Text = System.Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)  
  221. Me.ComboBox1.Items.AddRange(New String() {"*.*", "*.jpg", ".gif", "*.bmp", "*.tif", "*.png", "*.html", "*.htm", "*.asp", "*.aspx"})  
  222. ComboBox1.SelectedIndex = 1  
  223. TextBox2.Text = "例如*.jsp" 
  224. End Sub  
  225. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click  
  226. If TextBox2.Text <> "" Then  
  227. If Me.TextBox2.Text.Trim Like "*.*" Then  
  228. Me.ComboBox1.Items.Add(TextBox2.Text.Trim)  
  229. MeMe.ComboBox1.SelectedIndex = Me.ComboBox1.Items.Count - 1  
  230. End If  
  231. End If  
  232. End Sub  
  233. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click  
  234. Dim ofd As New FolderBrowserDialog  
  235. If ofd.ShowDialog = DialogResult.OK Then  
  236. Me.TextBox1.Text = ofd.SelectedPath  
  237. End If  
  238. End Sub  
  239. Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked  
  240. Dim p As New Process  
  241. p.Start(Me.LinkLabel1.Text)  
  242. End Sub  
  243. End Class 

以上就是VB.NET批量重命名处理,大家试试吧!

【编辑推荐】

  1. 程序员必看VB.NET CASE语句拓展篇
  2. 深入介绍VB.NET类库 SmartRWLocker技巧
  3. VB.NET复制读取音频文件到剪贴板小技巧
  4. 深入概括VB.NET运行环境
  5. 快速使用VB.NET搜索程序实例

网站栏目:VB.NET批量重命名修改大揭秘
本文网址:http://www.shufengxianlan.com/qtweb/news12/264662.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联