Renaming files

  • Thread starter Thread starter Dana Wilson
  • Start date Start date
D

Dana Wilson

Hi!

I have 4000+ PDF files that I need to rename. All I need to do is add 2
zeroes to the beginning of the filename (a file named 3668_new_file.pdf
should be 003668_new_file.pdf). I don't know alot about VB, but I'm
sure there is a way to write some code to automate this. Any
suggestions?

Thank you!
Dana
 
Dim sNames() as String, i as long, j as Long
Dim sPath as String, sName as String
Redim sNames(1 to 5000)
i = 1
sPath = "C:\My Documents"
sName = dir(sPath & "\" & "*.pdf")
Do while sName <> ""
sNames(i) = sName
i = i + 1
sName = dir()
Loop
for j = 1 to i-1
name sPath & "\" & sName(j) as sPath & "\00" & sName(j)
Next

Others may suggest doing the renaming in the first loop - this can cause
problems because you are changing the directory within a loop using DIR.
There is an MS Knowledge Base article that warns against doing this as it
could cause problems.
 
Back
Top