- A+
所属分类:系统Office
获取文件列表
新建bat文件,把它放在要处理的文件夹下双击运行。
DIR *.* >D:\LIST.TXT
批量修改文件名-1
如果文件名没有空格,直接用ren批处理代码。将rename.bat文件放在要改名文件夹下双击运行即可。
rename.bat代码如下,可以用Excel生成。
ren name1.txt newname1.txt
ren name2.txt newname2.txt
ren name3.txt newname3.txt
ren name4.txt newname4.txt
ren name5.txt newname5.txt
ren name6.txt newname6.txt
ren name7.txt newname7.txt
ren name8.txt newname8.txt
ren name9.txt newname9.txt
ren name10.txt newname10.txt
批量修改文件名-2
如果文件名中有空格,用Excel宏处理。操作Excel可以位于任何目录。
先运行第一个宏,获取文件名,然后在D列输入新文件名保存,运行第二个过程。
Sub 批量获取文件名()
Cells = ""
Dim sfso
Dim myPath As String
Dim Sh As Object
Dim Folder As Object
Application.ScreenUpdating = False
On Error Resume Next
Set sfso = CreateObject("Scripting.FileSystemObject")
Set Sh = CreateObject("shell.application")
Set Folder = Sh.BrowseForFolder(0, "", 0, "")
If Not Folder Is Nothing Then
myPath = Folder.Items.Item.Path
End If
Application.ScreenUpdating = True
Cells(1, 1) = "旧版名称"
Cells(1, 2) = "文件类型"
Cells(1, 3) = "所在位置"
Cells(1, 4) = "新版名称"
Call 直接提取文件名(myPath & "\")
End Sub
Sub 直接提取文件名(myPath As String)
Dim i As Long
Dim myTxt As String
i = Range("A1048576").End(xlUp).Row
myTxt = Dir(myPath, 31)
Do While myTxt <> ""
On Error Resume Next
If myTxt <> ThisWorkbook.Name And myTxt <> "." And myTxt <> ".." And myTxt <> "081226" Then
i = i + 1
Cells(i, 1) = "'" & myTxt
If (GetAttr(myPath & myTxt) And vbDirectory) = vbDirectory Then
Cells(i, 2) = "文件夹"
Else
Cells(i, 2) = "文件"
End If
Cells(i, 3) = Left(myPath, Len(myPath) - 1)
End If
myTxt = Dir
Loop
End Sub
Sub 批量重命名()
Dim y_name As String
Dim x_name As String
For i = 2 To Range("A1048576").End(xlUp).Row
y_name = Cells(i, 3) & "\" & Cells(i, 1)
x_name = Cells(i, 3) & "\" & Cells(i, 4)
On Error Resume Next
Name y_name As x_name
Next
End Sub

独角兽驿站
公众号