自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

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

開發(fā) 后端
文章主要介紹了VB.NET重命名的批量問題的解決,用一個(gè)實(shí)例來講解,代碼如:Public Class Form1 Inherits System.Windows.Forms.Form...

學(xué)習(xí)VB.NET編程的都知道重命名的問題,隨著我在工作中的積累,對(duì)VB.NET批量重命名的代碼編輯上做了一些總結(jié),下面給大家列舉一個(gè)VB.NET批量重命名代碼實(shí)例,希望可以給大家?guī)韼椭?/P>

  1. Imports System.IO  
  2. Public Class Form1  
  3. Inherits System.Windows.Forms.Form  
  4. #Region " Windows 窗體設(shè)計(jì)器生成的代碼 "  
  5. Public Sub New()  
  6. MyBase.New()  
  7. '該調(diào)用是 Windows 窗體設(shè)計(jì)器所必需的。  
  8. InitializeComponent()  
  9. '在 InitializeComponent() 調(diào)用之后添加任何初始化  
  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 窗體設(shè)計(jì)器所必需的  
  21. Private components As System.ComponentModel.IContainer  
  22. '注意: 以下過程是 Windows 窗體設(shè)計(jì)器所必需的  
  23. '可以使用 Windows 窗體設(shè)計(jì)器修改此過程。  
  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. <System.Diagnostics.DebuggerStepThrough()> 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 = "執(zhí)行" 
  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 = "目標(biāo)文件夾..." 
  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 = "狀態(tài)" 
  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("文件類型錯(cuò)誤")  
  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 = "正在復(fù)制到臨時(shí)目錄。。。" 
  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 = "復(fù)制到臨時(shí)目錄完成" 
  194. Me.Label2.Text = "正在刪除臨時(shí)文件。。。" 
  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("請(qǐng)選擇設(shè)置操作路徑和要文件類型")  
  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語(yǔ)句拓展篇
  2. 深入介紹VB.NET類庫(kù) SmartRWLocker技巧
  3. VB.NET復(fù)制讀取音頻文件到剪貼板小技巧
  4. 深入概括VB.NET運(yùn)行環(huán)境
  5. 快速使用VB.NET搜索程序?qū)嵗?/FONT>
責(zé)任編輯:田樹 來源: 博客
相關(guān)推薦

2009-10-28 12:28:52

VB.NET資源使用

2010-01-07 15:18:10

VB.NET常量

2010-01-15 10:47:15

VB.NET命名空間

2009-10-27 14:49:11

VB.NET命名規(guī)范

2009-11-10 15:36:24

VB.NET命名約定

2010-01-18 16:26:46

VB.NET數(shù)組賦值

2010-01-08 16:19:00

VB.NET類型單位命

2009-10-27 14:32:45

VB.NET類型級(jí)命名

2010-01-20 18:51:16

VB.NET修改系統(tǒng)時(shí)

2009-10-23 14:54:07

VB.NET命名空間

2011-06-17 11:05:22

VB.NET

2009-06-24 15:45:32

VB.NET

2009-11-10 11:01:05

VB.NET事件

2009-10-29 14:02:24

VB和VB.NET比較

2009-10-27 15:07:40

VB.NET支付寶接口

2009-10-20 14:21:55

VB.NET fnSi

2009-10-14 12:51:41

VB.NET Data

2009-11-02 17:12:01

VB和VB.NET

2010-01-08 16:28:31

VB.NET方法和屬性

2009-10-14 13:21:46

VB.NET Acco
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)