Thread: Renaming files
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Renaming files

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.

--
Regards,
Tom Ogilvy



"Dana Wilson" wrote in message
...
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



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!