王朝网络
分享
 
 
 

批量重命名(vb.net)

王朝c#·作者佚名  2006-01-14
宽屏版  字体: |||超大  

‘***************************

BY:wgscd

'http://www.wgscd.com

‘Date:2005

'Mail:wgscd@126.com

’****************************

Imports System.IO

Public Class Form1

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 Button1 As System.Windows.Forms.Button

Friend WithEvents TextBox1 As System.Windows.Forms.TextBox

Friend WithEvents Button2 As System.Windows.Forms.Button

Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox

Friend WithEvents TextBox2 As System.Windows.Forms.TextBox

Friend WithEvents Button3 As System.Windows.Forms.Button

Friend WithEvents Label1 As System.Windows.Forms.Label

Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar

Friend WithEvents Label2 As System.Windows.Forms.Label

Friend WithEvents CheckBox1 As System.Windows.Forms.CheckBox

Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu

Friend WithEvents LinkLabel1 As System.Windows.Forms.LinkLabel

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.Button1 = New System.Windows.Forms.Button

Me.TextBox1 = New System.Windows.Forms.TextBox

Me.Button2 = New System.Windows.Forms.Button

Me.ComboBox1 = New System.Windows.Forms.ComboBox

Me.TextBox2 = New System.Windows.Forms.TextBox

Me.Button3 = New System.Windows.Forms.Button

Me.Label1 = New System.Windows.Forms.Label

Me.ProgressBar1 = New System.Windows.Forms.ProgressBar

Me.Label2 = New System.Windows.Forms.Label

Me.CheckBox1 = New System.Windows.Forms.CheckBox

Me.MainMenu1 = New System.Windows.Forms.MainMenu

Me.LinkLabel1 = New System.Windows.Forms.LinkLabel

Me.SuspendLayout()

'

'Button1

'

Me.Button1.Location = New System.Drawing.Point(288, 120)

Me.Button1.Name = "Button1"

Me.Button1.Size = New System.Drawing.Size(112, 32)

Me.Button1.TabIndex = 0

Me.Button1.Text = "执行"

'

'TextBox1

'

Me.TextBox1.Location = New System.Drawing.Point(32, 40)

Me.TextBox1.Name = "TextBox1"

Me.TextBox1.Size = New System.Drawing.Size(272, 21)

Me.TextBox1.TabIndex = 1

Me.TextBox1.Text = "TextBox1"

'

'Button2

'

Me.Button2.Location = New System.Drawing.Point(336, 40)

Me.Button2.Name = "Button2"

Me.Button2.Size = New System.Drawing.Size(104, 23)

Me.Button2.TabIndex = 2

Me.Button2.Text = "目标文件夹..."

'

'ComboBox1

'

Me.ComboBox1.Location = New System.Drawing.Point(168, 88)

Me.ComboBox1.Name = "ComboBox1"

Me.ComboBox1.Size = New System.Drawing.Size(80, 20)

Me.ComboBox1.TabIndex = 3

Me.ComboBox1.Text = "ComboBox1"

'

'TextBox2

'

Me.TextBox2.Location = New System.Drawing.Point(168, 128)

Me.TextBox2.Name = "TextBox2"

Me.TextBox2.Size = New System.Drawing.Size(80, 21)

Me.TextBox2.TabIndex = 4

Me.TextBox2.Text = ""

'

'Button3

'

Me.Button3.Location = New System.Drawing.Point(40, 128)

Me.Button3.Name = "Button3"

Me.Button3.Size = New System.Drawing.Size(80, 23)

Me.Button3.TabIndex = 5

Me.Button3.Text = "新增文件类型"

'

'Label1

'

Me.Label1.Location = New System.Drawing.Point(40, 88)

Me.Label1.Name = "Label1"

Me.Label1.Size = New System.Drawing.Size(104, 23)

Me.Label1.TabIndex = 6

Me.Label1.Text = "要操作的文件类型"

'

'ProgressBar1

'

Me.ProgressBar1.Location = New System.Drawing.Point(40, 168)

Me.ProgressBar1.Name = "ProgressBar1"

Me.ProgressBar1.Size = New System.Drawing.Size(352, 16)

Me.ProgressBar1.TabIndex = 7

'

'Label2

'

Me.Label2.Location = New System.Drawing.Point(32, 192)

Me.Label2.Name = "Label2"

Me.Label2.Size = New System.Drawing.Size(240, 24)

Me.Label2.TabIndex = 8

Me.Label2.Text = "状态"

'

'CheckBox1

'

Me.CheckBox1.Location = New System.Drawing.Point(304, 80)

Me.CheckBox1.Name = "CheckBox1"

Me.CheckBox1.Size = New System.Drawing.Size(136, 24)

Me.CheckBox1.TabIndex = 9

Me.CheckBox1.Text = "完成后打开文件夹"

'

'LinkLabel1

'

Me.LinkLabel1.Location = New System.Drawing.Point(296, 200)

Me.LinkLabel1.Name = "LinkLabel1"

Me.LinkLabel1.Size = New System.Drawing.Size(144, 23)

Me.LinkLabel1.TabIndex = 10

Me.LinkLabel1.TabStop = True

Me.LinkLabel1.Text = "http://www.wgscd.com"

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)

Me.ClientSize = New System.Drawing.Size(464, 238)

Me.Controls.Add(Me.LinkLabel1)

Me.Controls.Add(Me.CheckBox1)

Me.Controls.Add(Me.Label2)

Me.Controls.Add(Me.ProgressBar1)

Me.Controls.Add(Me.Label1)

Me.Controls.Add(Me.Button3)

Me.Controls.Add(Me.TextBox2)

Me.Controls.Add(Me.ComboBox1)

Me.Controls.Add(Me.Button2)

Me.Controls.Add(Me.TextBox1)

Me.Controls.Add(Me.Button1)

Me.Menu = Me.MainMenu1

Me.Name = "Form1"

Me.Text = "批量重命名 wgscd 2005"

Me.ResumeLayout(False)

End Sub

#End Region

Dim Path As String = ""

Dim Filter As String = "*.*"

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Filter = Me.ComboBox1.SelectedItem

Dim dir As DirectoryInfo

Path = Me.TextBox1.Text

If Path <> "" AndAlso Me.ComboBox1.Text <> "" Then

' If Me.TextBox1.Text.Trim.Length > 6 Then

' MsgBox("文件类型错误")

' Exit Sub

' End If

Dim D As New DirectoryInfo("Temp")

If D.Exists = False Then

D.Create()

End If

dir = New DirectoryInfo(Me.TextBox1.Text)

Dim lenth As Integer = dir.GetFiles(Filter).Length

If lenth > 0 Then

Me.ProgressBar1.Value = 0

Me.ProgressBar1.Maximum = lenth + 1

Me.Label2.Text = "正在复制到临时目录。。。"

Dim fi As FileInfo

Dim i As Integer = 1

For Each fi In dir.GetFiles(Filter)

Dim Temp As String = fi.Name

Dim Extention As String = fi.Extension

fi.CopyTo("Temp\" & i & Extention, True)

fi.Delete()

i += 1

Me.ProgressBar1.Value = i

Next

Me.ProgressBar1.Value = 0

Me.Label2.Text = "复制到临时目录完成"

Me.Label2.Text = "正在删除临时文件。。。"

dir = New DirectoryInfo("Temp")

If dir.GetFiles(Filter).Length Then

Dim fi2 As FileInfo

Dim j As Integer = 1

For Each fi2 In dir.GetFiles(Filter)

Dim Temp As String = fi2.Name

Dim Extention As String = fi2.Extension

fi2.CopyTo(Path & "\" & j & Extention, True)

fi2.Delete()

j += 1

Me.ProgressBar1.Value = j

Next

Me.Label2.Text = "处理完成"

If Me.CheckBox1.Checked Then

Dim p As New Process

p.Start(Path)

End If

End If

Else : Exit Sub

End If

Else

MsgBox("请选择设置操作路径和要文件类型")

End If

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.TextBox1.Text = System.Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)

Me.ComboBox1.Items.AddRange(New String() {"*.*", "*.jpg", ".gif", "*.bmp", "*.tif", "*.png", "*.html", "*.htm", "*.asp", "*.aspx"})

ComboBox1.SelectedIndex = 1

TextBox2.Text = "例如*.jsp"

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

If TextBox2.Text <> "" Then

If Me.TextBox2.Text.Trim Like "*.*" Then

Me.ComboBox1.Items.Add(TextBox2.Text.Trim)

Me.ComboBox1.SelectedIndex = Me.ComboBox1.Items.Count - 1

End If

End If

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim ofd As New FolderBrowserDialog

If ofd.ShowDialog = DialogResult.OK Then

Me.TextBox1.Text = ofd.SelectedPath

End If

End Sub

Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked

Dim p As New Process

p.Start(Me.LinkLabel1.Text)

End Sub

End Class

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
>>返回首页<<
推荐阅读
 
 
频道精选
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有