专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > VB Dotnet

怎么在window下更改文件名

发布时间:2011-06-23 15:55:04 文章来源:www.iduyao.cn 采编人员:星星草
如何在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()
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: