我发现 adobes bates 编号工具存在问题,其中文件名弄乱了它们的编号顺序。我希望编写一个脚本,用户可以单击并为所有文件添加文件夹扩展名。然后脚本会在文件夹中的所有文件名前面加上000001filename.pdf
,000002filename.pdf
等。
我以前从未组合过脚本,但我找到了重命名或前置的脚本,而且我找不到任何可以用前面的 0 顺序重命名的东西。
这是我到目前为止所拥有的:
Dim iloop As Integer
Dim iFileNumber As Integer
Dim sPrefix As String
Dim sNewFileName As String
Dim arr() As String
'Get array of all pdfs from the selected directory
arr = System.IO.Directory.GetFiles(strPath, "*.PDF")
'loop through the array
For iloop = 0 To UBound(arr)
'Create a prefix for each file
iFileNumber = iloop + 1
Select Case iFileNumber
Case 0 To 9 : sPrefix = "00000" & iFileNumber
Case 10 To 99 : sPrefix = "0000" & iFileNumber
Case 100 To 999 : sPrefix = "000" & iFileNumber
Case 1000 To 9999 : sPrefix = "00" & iFileNumber
Case 10000 To 99999 : sPrefix = "0" & iFileNumber
Case Else : sPrefix = iFileNumber
End Select
Dim arr2() As String
'split the path by the / symbol to get the filename
arr2 = Split(arr(iloop),"\")
'Add the prefix to the front of the filename, filename will be the last item in the array.
arr2(uBound(arr2)) = sPrefix & arr2(uBound(arr2))
'Put the new path and filename back together
sNewFileName = Join(arr2,"\")
'Rename the file with the new filename
System.IO.File.Move(arr(iloop),sNewFileName)
Next