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.
 
Tom,

Thanks so much!!! It worked perfectly!! You saved me so much time!!

Dana
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top