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

Rename using "mid" or 'right"?

Status
Not open for further replies.

szander

IS-IT--Management
Jan 23, 2003
16
US
I need to rename a large number of files only using the 4 characters to the left of '.' before the extension.

example - original file name is - rebate5664.tif
needs to be renamed to 5664.tif

I have already dealt with any duplications.

Thanks for the help.
 
Maybe what you really need is the InStrRev() function to pick out the position of the first period starting from the end of the string. Then just take this position, subtract 4, and use Mid from that point.

posPeriod = InStrRev(strOldFileName, ".")
strNewFileName = Mid(strOldFileName, (posPeriod - 4), 4)

 
What Sheco says, but...

Code:
strNewFileName = Mid(strOldFileName, (posPeriod - 4))

drop the , 4 from it or you'll lose your extention

I love small animals, especially with a good brown gravy....
 
Oh, heh yeah, good catch! I was focused only on the 4 wanted characters and I forgot all about the real problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top