Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rename files with numbers

Status
Not open for further replies.

fjdurbin

Technical User
Dec 14, 2010
2
0
0
US
I have a large number of files that are named abc_page1, abc_page2 and I need them be be named abc_page001, abc_page002, etc.

Does anyone have an example?...JD
 
Code:
set objFSO = CreateObject("Scripting.FileSystemObject")
set objFiles = objFSO.GetFolder("C:\temp\pages").Files

for each objFile in objFiles
   strFile = objFile.Name
   
   'get page number
   intPos = inStr(strFile, "_page") + 4
   strNum = right(strFile, len(strFile) - intPos)

   'make new number
   strNewNum = right("000" & strNum, 3)

   'rename objFile
   objFile.Name = replace(strFile, strNum, strNewNum)
next

-Geates


"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top