批量重命名

 
Imports System.IO

Public Class Form1
    
Inherits System.Windows.Forms.Form

Windows 窗体设计器生成的代码
    
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值