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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to rename a file incrementally.

Status
Not open for further replies.

shoppa

MIS
May 30, 2003
1
US
Hello all, I am very new to VBScript.

I am trying to create a script to rename a file incrementally. So essentially it would be a folder with a script that runs nightly renaming one file, then deleting the original file copied there.

so the directory after 4 days would look like this
---------------
file0001.mdb
file0002.mdb
file0003.mdb
file0004.mdb

I have the script to copy the file to the directory, I just dont know how to make it rename it incrementally. Any help much appreciated!

 
dim mystr,sfilename,i,strlength,pos,inumber
sfilename=file0001.mdb
pos=instr(sfilename,".")
inumber=Mid(sfilename,4,pos-4)

this gives u the value 0001 which is what we have to increment

inumber= CInt(inumber)+ 1

mystr=CStr(inumber)

Do While Len(mystr)<4
mystr=&quot;0&quot; & mystr

Loop

at the end your filename =

sfilename= &quot;file&quot; & mystr & &quot;.mdb&quot;












 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top