Imports System.Runtime.InteropServices 
Public Class Form1 
    
Inherits System.Windows.Forms.Form 
    
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu 

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

    Public Sub New() 
        
MyBase.New() 

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

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

    
End Sub


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

    
'注意: 以下过程是 Windows 窗体设计器所必需的 
    '可以使用 Windows 窗体设计器修改此过程。 
    '不要使用代码编辑器修改它。 
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox 
    
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox 
    
Friend WithEvents Button2 As System.Windows.Forms.Button 
    
Friend WithEvents Button3 As System.Windows.Forms.Button 
    
Friend WithEvents ListBox2 As System.Windows.Forms.ListBox 
    
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox 
    
Friend WithEvents StatusBar1 As System.Windows.Forms.StatusBar 
    
Friend WithEvents Timer1 As System.Windows.Forms.Timer 
    
Friend WithEvents Label1 As System.Windows.Forms.Label 
    
Friend WithEvents Button1 As System.Windows.Forms.Button 
    
Friend WithEvents Panel1 As System.Windows.Forms.Panel 
    
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox 
    
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox 
    
Friend WithEvents TextBox4 As System.Windows.Forms.TextBox 
    
Friend WithEvents Button5 As System.Windows.Forms.Button 
    
Friend WithEvents Timer2 As System.Windows.Forms.Timer 
    
Friend WithEvents Label2 As System.Windows.Forms.Label 
    
Friend WithEvents Label3 As System.Windows.Forms.Label 
    
Friend WithEvents Label4 As System.Windows.Forms.Label 
    
Private Sub InitializeComponent() 
        
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1)) 
        Me.MainMenu1 
= New System.Windows.Forms.MainMenu 
        Me.ListBox1 
= New System.Windows.Forms.ListBox 
        Me.TextBox2 
= New System.Windows.Forms.TextBox 
        Me.Button2 
= New System.Windows.Forms.Button 
        Me.Button3 
= New System.Windows.Forms.Button 
        Me.ListBox2 
= New System.Windows.Forms.ListBox 
        Me.PictureBox1 
= New System.Windows.Forms.PictureBox 
        Me.StatusBar1 
= New System.Windows.Forms.StatusBar 
        Me.Timer1 
= New System.Windows.Forms.Timer 
        Me.Label1 
= New System.Windows.Forms.Label 
        Me.Button1 
= New System.Windows.Forms.Button 
        Me.Panel1 
= New System.Windows.Forms.Panel 
        Me.Label4 
= New System.Windows.Forms.Label 
        Me.Label3 
= New System.Windows.Forms.Label 
        Me.Label2 
= New System.Windows.Forms.Label 
        Me.Button5 
= New System.Windows.Forms.Button 
        Me.TextBox4 
= New System.Windows.Forms.TextBox 
        Me.TextBox3 
= New System.Windows.Forms.TextBox 
        Me.TextBox1 
= New System.Windows.Forms.TextBox 
        Me.Timer2 
= New System.Windows.Forms.Timer 
        
' 
        'ListBox1 
        ' 
        Me.ListBox1.Location = New System.Drawing.Point(856
        Me.ListBox1.Size 
= New System.Drawing.Size(21674
        
' 
        'TextBox2 
        ' 
        Me.TextBox2.BackColor = System.Drawing.SystemColors.Info 
        Me.TextBox2.Enabled 
= False 
        Me.TextBox2.Font 
= New System.Drawing.Font("宋体"7.5!, System.Drawing.FontStyle.Regular) 
        Me.TextBox2.ForeColor 
= System.Drawing.Color.Black 
        Me.TextBox2.Location 
= New System.Drawing.Point(816
        Me.TextBox2.Multiline 
= True 
        Me.TextBox2.Size 
= New System.Drawing.Size(21632
        Me.TextBox2.Text 
= "TextBox2" 
        
' 
        'Button2 
        ' 
        Me.Button2.Location = New System.Drawing.Point(8200
        Me.Button2.Size 
= New System.Drawing.Size(6424
        Me.Button2.Text 
= "下级目录" 
        
' 
        'Button3 
        ' 
        Me.Button3.Location = New System.Drawing.Point(144200
        Me.Button3.Size 
= New System.Drawing.Size(8024
        Me.Button3.Text 
= "批量改文件名" 
        
' 
        'ListBox2 
        ' 
        Me.ListBox2.Location = New System.Drawing.Point(8128
        Me.ListBox2.Size 
= New System.Drawing.Size(21662
        
' 
        'PictureBox1 
        ' 
        Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image) 
        Me.PictureBox1.Location 
= New System.Drawing.Point(80
        Me.PictureBox1.Size 
= New System.Drawing.Size(1616
        Me.PictureBox1.SizeMode 
= System.Windows.Forms.PictureBoxSizeMode.StretchImage 
        
' 
        'StatusBar1 
        ' 
        Me.StatusBar1.Location = New System.Drawing.Point(0272
        Me.StatusBar1.Size 
= New System.Drawing.Size(23416
        Me.StatusBar1.Text 
= "design by xy" 
        
' 
        'Timer1 
        ' 
        Me.Timer1.Enabled = True 
        Me.Timer1.Interval 
= 2000 
        
' 
        'Label1 
        ' 
        Me.Label1.Location = New System.Drawing.Point(8232
        Me.Label1.Size 
= New System.Drawing.Size(21640
        
' 
        'Button1 
        ' 
        Me.Button1.Location = New System.Drawing.Point(80200
        Me.Button1.Size 
= New System.Drawing.Size(5624
        Me.Button1.Text 
= "设置" 
        
' 
        'Panel1 
        ' 
        Me.Panel1.BackColor = System.Drawing.SystemColors.Info 
        Me.Panel1.Controls.Add(Me.Label4) 
        Me.Panel1.Controls.Add(Me.Label3) 
        Me.Panel1.Controls.Add(Me.Label2) 
        Me.Panel1.Controls.Add(Me.Button5) 
        Me.Panel1.Controls.Add(Me.TextBox4) 
        Me.Panel1.Controls.Add(Me.TextBox3) 
        Me.Panel1.Controls.Add(Me.TextBox1) 
        Me.Panel1.Size 
= New System.Drawing.Size(2400
        
' 
        'Label4 
        ' 
        Me.Label4.Location = New System.Drawing.Point(1696
        Me.Label4.Size 
= New System.Drawing.Size(3216
        Me.Label4.Text 
= "前缀" 
        
' 
        'Label3 
        ' 
        Me.Label3.Location = New System.Drawing.Point(1656
        Me.Label3.Size 
= New System.Drawing.Size(8016
        Me.Label3.Text 
= "目标扩展名" 
        
' 
        'Label2 
        ' 
        Me.Label2.Location = New System.Drawing.Point(1616
        Me.Label2.Size 
= New System.Drawing.Size(7216
        Me.Label2.Text 
= "筛选扩展名" 
        
' 
        'Button5 
        ' 
        Me.Button5.Location = New System.Drawing.Point(120136
        Me.Button5.Size 
= New System.Drawing.Size(9632
        Me.Button5.Text 
= "确定" 
        
' 
        'TextBox4 
        ' 
        Me.TextBox4.Location = New System.Drawing.Point(12096
        Me.TextBox4.Size 
= New System.Drawing.Size(9621
        Me.TextBox4.Text 
= "" 
        
' 
        'TextBox3 
        ' 
        Me.TextBox3.Location = New System.Drawing.Point(12056
        Me.TextBox3.Size 
= New System.Drawing.Size(9621
        Me.TextBox3.Text 
= "jpg" 
        
' 
        'TextBox1 
        ' 
        Me.TextBox1.Location = New System.Drawing.Point(12016
        Me.TextBox1.Size 
= New System.Drawing.Size(9621
        Me.TextBox1.Text 
= "jpg" 
        
' 
        'Timer2 
        ' 
        Me.Timer2.Interval = 50 
        
' 
        'Form1 
        ' 
        Me.ClientSize = New System.Drawing.Size(234288
        Me.Controls.Add(Me.Panel1) 
        Me.Controls.Add(Me.Button1) 
        Me.Controls.Add(Me.Label1) 
        Me.Controls.Add(Me.StatusBar1) 
        Me.Controls.Add(Me.PictureBox1) 
        Me.Controls.Add(Me.ListBox2) 
        Me.Controls.Add(Me.Button3) 
        Me.Controls.Add(Me.Button2) 
        Me.Controls.Add(Me.TextBox2) 
        Me.Controls.Add(Me.ListBox1) 
        Me.Menu 
= Me.MainMenu1 
        Me.Text 
= "批量改名" 

    
End Sub


#
End Region 
    
Dim t As Integer 
    
Dim t2 As Boolean 
    
Const SIPF_OFF As Integer = &H0 
    
Const SIPF_ON As Integer = &H1 

    
<DllImport("coredll.dll")> _ 
    
Private Shared Function SipShowIM(ByVal dwFlag As IntegerAs Integer 
    
End Function
 
    
Private Function listflr(ByVal currentdir As StringAs Boolean 
        
Dim thisdir As New System.IO.DirectoryInfo(currentdir) 
        
Dim subdirectores() As System.IO.FileInfo 
        subdirectores 
= thisdir.GetFiles("*.*"
        
Dim subdir As System.IO.FileInfo 
        
For Each subdir In subdirectores 
            
With subdir 
                ListBox2.Items.Add(.Name) 
            
End With 
        
Next 
    
End Function
 
    
Private Function listdir(ByVal pat As StringAs Boolean 
        
Dim thisdir As New System.IO.DirectoryInfo(pat) 
        
Dim sunbdir() As System.IO.DirectoryInfo 
        sunbdir 
= thisdir.GetDirectories 
        
Dim subdir As System.IO.DirectoryInfo 
        ListBox1.Items.Clear() 
        
For Each subdir In sunbdir 
            ListBox1.Items.Add(subdir.FullName) 
        
Next 
    
End Function
 

    
Private Sub Button2_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button2.Click 
        listdir(TextBox2.Text) 
        ListBox2.Items.Clear() 
    
End Sub
 

    
Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load 
        TextBox2.Text 
= "\" 
        ListBox1.Items.Add(
"\"
        Me.Menu 
= Nothing 
        
Dim path As String 
    
End Sub
 

    
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged 
        TextBox2.Text 
= ListBox1.SelectedItem 
        ListBox2.Items.Clear() 
        listflr(TextBox2.Text) 
    
End Sub
 
    
Private Function changename(ByVal pathr As StringAs Boolean 
        
Dim thisdir As New System.IO.DirectoryInfo(pathr) 
        
Dim subdirectores() As System.IO.FileInfo 
        subdirectores 
= thisdir.GetFiles("*." & TextBox1.Text) 
        
Dim subdir As System.IO.FileInfo 
        
Dim i As Integer 
        
Try 

            
For Each subdir In subdirectores 
                i 
= i + 1 
                
Select Case i 
                    
Case Is < 10 
                        subdir.MoveTo(pathr 
& "\" & TextBox4.Text & "000" & i & "." & TextBox3.Text) 

                    
Case Is < 100 
                        subdir.MoveTo(pathr 
& "\" & TextBox4.Text & "00" & i & "." & TextBox3.Text) 

                    
Case Is < 1000 
                        subdir.MoveTo(pathr 
& "\" & TextBox4.Text & "0" & i & "." & TextBox3.Text) 

                    
Case Else 
                        subdir.MoveTo(pathr 
& "\" & TextBox4.Text & i & "." & TextBox3.Text) 

                
End Select

            
Next 
            ListBox2.Items.Clear() 
            listflr(TextBox2.Text) 
        
Catch 
            
If Err.Number = 57 Then 
                i 
= 0 
                
For Each subdir In subdirectores 
                    i 
= i + 1 
                    
Select Case i 
                        
Case Is < 10 
                            subdir.MoveTo(pathr 
& "\" & TextBox4.Text & "000" & i & ".ttt"

                        
Case Is < 100 
                            subdir.MoveTo(pathr 
& "\" & TextBox4.Text & "00" & i & ".ttt"

                        
Case Is < 1000 
                            subdir.MoveTo(pathr 
& "\" & TextBox4.Text & "0" & i & ".ttt"

                        
Case Else 
                            subdir.MoveTo(pathr 
& "\" & TextBox4.Text & i & ".ttt"

                    
End Select 
                
Next 
                changename2(TextBox2.Text) 
            
Else 
                
MsgBox(Err.Description, , "出错"
            
End If 

        
End Try 
    
End Function
 

    
Private Sub Button3_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button3.Click 
        changename(TextBox2.Text) 
    
End Sub
 

    
Private Sub PictureBox1_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles PictureBox1.Click 
        ListBox1.Items.Clear() 
        ListBox1.Items.Add(
"\"
        ListBox2.Items.Clear() 
    
End Sub
 

    
Private Sub Timer1_Tick(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Timer1.Tick 
        
Select Case t 
            
Case 0 
                Label1.Text 
= "设置里可以进行转换的相应设置" 
                t 
+= 1 
            
Case 1 
                Label1.Text 
= "单击面包图标回到根目录" 
                t 
+= 1 
            
Case 2 
                Label1.Text 
= "目录路径显示不完全可以在黄色区域预览" 
                t 
= 0 
        
End Select 
    
End Sub
 

    
Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button1.Click 
        t2 
= False 
        Timer2.Enabled 
= True 

        SipShowIM(
1
    
End Sub
 


    
Private Sub Button5_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button5.Click 
        
If TextBox1.Text <> "" And TextBox3.Text <> "" Then 
            t2 
= True 
            Timer2.Enabled 
= True 
            SipShowIM(
2
        
Else 
            
MsgBox("筛选扩展名或目标扩展名不能为空!", MsgBoxStyle.OKOnly, "错误"
            SipShowIM(
1
        
End If 
    
End Sub
 

    
Private Sub Timer2_Tick(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Timer2.Tick 
        
Select Case t2 
            
Case False 
                
If Panel1.Height >= 190 Then 
                    Timer2.Enabled 
= False 
                
Else 
                    Panel1.Height 
= Panel1.Height + 10 
                
End If 
            
Case True 
                
If Panel1.Height <= 0 Then Timer2.Enabled = False 
                Panel1.Height 
= Panel1.Height - 10 
        
End Select 

    
End Sub
 
    
Private Function changename2(ByVal pathr As StringAs Boolean 
        
Dim thisdir As New System.IO.DirectoryInfo(pathr) 
        
Dim subdirectores() As System.IO.FileInfo 
        subdirectores 
= thisdir.GetFiles("*.ttt"
        
Dim subdir As System.IO.FileInfo 
        
Dim i As Integer 
        
Try 

            
For Each subdir In subdirectores 
                i 
= i + 1 
                
Select Case i 
                    
Case Is < 10 
                        subdir.MoveTo(pathr 
& "\" & TextBox4.Text & "000" & i & "." & TextBox3.Text) 

                    
Case Is < 100 
                        subdir.MoveTo(pathr 
& "\" & TextBox4.Text & "00" & i & "." & TextBox3.Text) 

                    
Case Is < 1000 
                        subdir.MoveTo(pathr 
& "\" & TextBox4.Text & "0" & i & "." & TextBox3.Text) 

                    
Case Else 
                        subdir.MoveTo(pathr 
& "\" & TextBox4.Text & i & "." & TextBox3.Text) 

                
End Select

            
Next 
            ListBox2.Items.Clear() 
            listflr(TextBox2.Text) 
        
Catch 
            
MsgBox(Err.Description) 

        
End Try 
    
End Function
 
End Class
 

posted on 2004-12-20 19:07  xyocj  阅读(767)  评论(0编辑  收藏  举报