首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

怎么在window下更改文件名

2012-02-02 
如何在window下更改文件名?现有如下需求:比如有如下文件:神雕侠侣01(影视).rmvb神雕侠侣02(影视).rmvb神雕

如何在window下更改文件名?
现有如下需求:
比如有如下文件:
神雕侠侣01(影视).rmvb
神雕侠侣02(影视).rmvb
神雕侠侣03(影视).rmvb
神雕侠侣04(影视).rmvb
神雕侠侣05(影视).rmvb

如何批量改成:
01.rmvb
02.rmvb
03.rmvb
04.rmvb
05.rmvb

求助...

[解决办法]
' 这个改进了一点了,但还不够健壮
' 在窗体中什么控件都不用加
' 可以用Up和Down调整ListBox中的项,从上到下从1开始重命名
' 如果只是需要批量更名的话,还是建议使用《拖把更名器》

Imports System.Data
Imports System.Data.OleDb
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.IO
Imports System.IO.Path
Imports System.Threading
Imports System.Xml

Public Class Form1

Dim ListBox1 As New ListBox
Dim Button1 As New Button
Dim Button2 As New Button
Dim Button3 As New Button
Dim Button4 As New Button
Dim strFileNames() As String

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
With ListBox1
.Left = 12
.Top = 12
.Width = Me.Width - 32
.Height = 100
End With
With Button1
.Left = 12
.Top = 12 + ListBox1.Height + 6
.Width = 90
.Text = "Select Files "
End With
With Button2
.Left = 12 + Button1.Width + 6
.Top = Button1.Top
.Width = 70
.Text = "Rename "
End With
With Button3
.Left = Button2.Right + 6
.Top = Button1.Top
.Width = 40
.Text = "Up "
End With
With Button4
.Left = Button3.Right + 6
.Top = Button1.Top
.Width = 40
.Text = "Down "
End With
AddHandler ListBox1.SelectedIndexChanged, AddressOf ListBox1_SelectedIndexChanged
AddHandler Button1.Click, AddressOf Button1_Click
AddHandler Button2.Click, AddressOf Button2_Click
AddHandler Button3.Click, AddressOf Button3_Click
AddHandler Button4.Click, AddressOf Button4_Click
Me.Controls.Add(ListBox1)
Me.Controls.Add(Button1)
Me.Controls.Add(Button2)
Me.Controls.Add(Button3)
Me.Controls.Add(Button4)
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim strFileName As String
OpenFileDialog1.Multiselect = True
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
strFileNames = OpenFileDialog1.FileNames
For Each strFileName In strFileNames
ListBox1.Items.Add(strFileName)
Next
Button2.Enabled = True
End If
End Sub

Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim strFileName As String
For c As Int32 = 0 To ListBox1.Items.Count - 1
strFileNames(c) = ListBox1.Items(c).ToString
Next
Dim i As Int32 = 1
For Each strFileName In strFileNames
Dim strNewFileName As String = Path.GetDirectoryName(strFileName) & "\ " & Format(i, "00 ") & Path.GetExtension(strFileName)
Rename(strFileName, strNewFileName)
i += 1
Next
ListBox1.Items.Clear()


MsgBox( "Rename Completed! ")
End Sub

Private Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim i As Int32 = ListBox1.SelectedIndex
Dim s As String
s = ListBox1.SelectedItem.ToString
ListBox1.Items(i) = ListBox1.Items(i - 1)
ListBox1.Items(i - 1) = s
ListBox1.SelectedIndex = i - 1
End Sub

Private Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim i As Int32 = ListBox1.SelectedIndex
Dim s As String
s = ListBox1.SelectedItem.ToString
ListBox1.Items(i) = ListBox1.Items(i + 1)
ListBox1.Items(i + 1) = s
ListBox1.SelectedIndex = i + 1
End Sub

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Select Case ListBox1.SelectedIndex
Case 0
Button3.Enabled = False
Button4.Enabled = True
Case ListBox1.Items.Count - 1
Button3.Enabled = True
Button4.Enabled = False
Case Else
Button3.Enabled = True
Button4.Enabled = True
End Select
End Sub
End Class

热点排行