用VB批量重命名文件,如何实现?
我想设置一个TEXT框,里面输入"20101007-",然后,我所打开的文件夹里的文档名称都加TEXT1里的部分也就是12345.txt命名为20101007-12345...
我想设置一个TEXT框,里面输入"20101007-",然后,我所打开的文件夹里的文档名称都加TEXT1里的部分
也就是 12345.txt命名为20101007-12345.txt
我的QQ是1466536006,会做的大大请加QQ,我有改文档的代码,现在只缺重命名部分,请帮我改下~~~ 展开
也就是 12345.txt命名为20101007-12345.txt
我的QQ是1466536006,会做的大大请加QQ,我有改文档的代码,现在只缺重命名部分,请帮我改下~~~ 展开
3个回答
展开全部
方法一:Dim fpPrivate Sub refilename(folderspec)Dim fs, f, f1, fc, sm, hzSet fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)Set fc = f.FilesFor Each f1 In fc
hz = Mid(f1.Name, InStrRev(f1.Name, "."))
Name f1 As fp & "20101007-" & hz
NextMsgBox "修改完成"End SubPrivate Sub Command1_Click()fp = "E:\emot\xhh\"'这里设置文件夹路径,根的需要来修改
If Right(fp, 1) <> "\" And Right(fp, 1) <> "/"
Then fp = fp & "\"Call refilename(fp)
’调用上面的自定义函数,改名End Sub........
方法二: '将f:\123\文件下的txt文件改名
Dim files() As String '用于贮存文件名
Dim length As Integer = 0 'files数组长度
Dim fileName As String = Dir$("f:\123\*.txt") '得到第一个.txt文件的文件名
'Dim g As Graphics = Me.CreateGraphics
Do While fileName <> ""
'g.DrawString(length, Font, Brushes.Red, length * 10, length * 10)
ReDim Preserve files(length)
files(length) = fileName
length = files.Length
fileName = Dir$() '得到下一个.txt文件的文件名
Loop
For i = 0 To length - 1
Dim oldfileName As String = "f:\123\" + files(i)
Dim newfileName As String = "f:\123\" + "20101007_"+ files(i)
Rename(oldfileName, newfileName) '修改文件名
Next
Set f = fs.GetFolder(folderspec)Set fc = f.FilesFor Each f1 In fc
hz = Mid(f1.Name, InStrRev(f1.Name, "."))
Name f1 As fp & "20101007-" & hz
NextMsgBox "修改完成"End SubPrivate Sub Command1_Click()fp = "E:\emot\xhh\"'这里设置文件夹路径,根的需要来修改
If Right(fp, 1) <> "\" And Right(fp, 1) <> "/"
Then fp = fp & "\"Call refilename(fp)
’调用上面的自定义函数,改名End Sub........
方法二: '将f:\123\文件下的txt文件改名
Dim files() As String '用于贮存文件名
Dim length As Integer = 0 'files数组长度
Dim fileName As String = Dir$("f:\123\*.txt") '得到第一个.txt文件的文件名
'Dim g As Graphics = Me.CreateGraphics
Do While fileName <> ""
'g.DrawString(length, Font, Brushes.Red, length * 10, length * 10)
ReDim Preserve files(length)
files(length) = fileName
length = files.Length
fileName = Dir$() '得到下一个.txt文件的文件名
Loop
For i = 0 To length - 1
Dim oldfileName As String = "f:\123\" + files(i)
Dim newfileName As String = "f:\123\" + "20101007_"+ files(i)
Rename(oldfileName, newfileName) '修改文件名
Next
展开全部
Replace(a,b,c)
在a中寻找b 替换成c
private Sub Command1_Click()
Dim oldName
Dim NewName As String, i As Integer, a As Integer
oldName = Array("z:\1.txt", "z:\2.txt")
For i = 0 To UBound(oldName)
a = InStr(1, oldName(i), "\")
NewName = Replace(oldName(i), Mid(oldName(i), 1, a), Mid(oldName(i), 1, a) & Chr(97 + i))
Name oldName(i) As NewName
Next
End Sub
自己再加工一下吧
在a中寻找b 替换成c
private Sub Command1_Click()
Dim oldName
Dim NewName As String, i As Integer, a As Integer
oldName = Array("z:\1.txt", "z:\2.txt")
For i = 0 To UBound(oldName)
a = InStr(1, oldName(i), "\")
NewName = Replace(oldName(i), Mid(oldName(i), 1, a), Mid(oldName(i), 1, a) & Chr(97 + i))
Name oldName(i) As NewName
Next
End Sub
自己再加工一下吧
参考资料: http://zhidao.baidu.com/question/110662534.html?fr=ala0
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
思路一:
Dim fp
Private Sub refilename(folderspec)
Dim fs, f, f1, fc, sm, hz
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.Files
For Each f1 In fc
hz = Mid(f1.Name, InStrRev(f1.Name, "."))
Name f1 As fp & "20101007-" & hz
Next
MsgBox "修改完成"
End Sub
Private Sub Command1_Click()
fp = "E:\emot\xhh\"'这里设置文件夹路径,根据你的需要来修改
If Right(fp, 1) <> "\" And Right(fp, 1) <> "/" Then fp = fp & "\"
Call refilename(fp)’调用上面的自定义函数,改名
End Sub
........
思路二:
'将f:\123\文件下的txt文件改名
Dim files() As String '用于贮存文件名
Dim length As Integer = 0 'files数组长度
Dim fileName As String = Dir$("f:\123\*.txt") '得到第一个.txt文件的文件名
'Dim g As Graphics = Me.CreateGraphics
Do While fileName <> ""
'g.DrawString(length, Font, Brushes.Red, length * 10, length * 10)
ReDim Preserve files(length)
files(length) = fileName
length = files.Length
fileName = Dir$() '得到下一个.txt文件的文件名
Loop
For i = 0 To length - 1
Dim oldfileName As String = "f:\123\" + files(i)
Dim newfileName As String = "f:\123\" + "20101007_"+ files(i)
Rename(oldfileName, newfileName) '修改文件名
Next
..........
仅供参考。........黑龙江省..张志晨.........
Dim fp
Private Sub refilename(folderspec)
Dim fs, f, f1, fc, sm, hz
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(folderspec)
Set fc = f.Files
For Each f1 In fc
hz = Mid(f1.Name, InStrRev(f1.Name, "."))
Name f1 As fp & "20101007-" & hz
Next
MsgBox "修改完成"
End Sub
Private Sub Command1_Click()
fp = "E:\emot\xhh\"'这里设置文件夹路径,根据你的需要来修改
If Right(fp, 1) <> "\" And Right(fp, 1) <> "/" Then fp = fp & "\"
Call refilename(fp)’调用上面的自定义函数,改名
End Sub
........
思路二:
'将f:\123\文件下的txt文件改名
Dim files() As String '用于贮存文件名
Dim length As Integer = 0 'files数组长度
Dim fileName As String = Dir$("f:\123\*.txt") '得到第一个.txt文件的文件名
'Dim g As Graphics = Me.CreateGraphics
Do While fileName <> ""
'g.DrawString(length, Font, Brushes.Red, length * 10, length * 10)
ReDim Preserve files(length)
files(length) = fileName
length = files.Length
fileName = Dir$() '得到下一个.txt文件的文件名
Loop
For i = 0 To length - 1
Dim oldfileName As String = "f:\123\" + files(i)
Dim newfileName As String = "f:\123\" + "20101007_"+ files(i)
Rename(oldfileName, newfileName) '修改文件名
Next
..........
仅供参考。........黑龙江省..张志晨.........
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询