Renaming a bunch of files

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
jimbo101974
Posts: 40
Joined: Wed Oct 31, 2007 11:01 pm

Renaming a bunch of files

Post by jimbo101974 » Wed May 07, 2008 10:13 pm

Hello all
I need some help automating the renaming of a large group of files. I have an application that stores a large number of files in a folder. Occasionally one of these files gets corrupt and must be deleted. The files are sequential by the file extension. So I may have something that looks like this. All in the same folder.

XY123456.f01
XY123456.f02
XY123456.f03
XY123456.f04
XY123456.f05
XY234567.f01
XY234567.f02
XY234567.f03

Usually the file ext's go as high as .f55. You'll notice the different file names XY123456 and XY234567 belong to different groups and while stored the same place do not belong to the same part of the application.

Here's what I want to do let say in the group XY123456 the file with ext .f02 gets corrupt. I need to rename .f03 -> f02 and then continue to subtract 1 from the number in the file ext until I get to the last file in that group. What I do not want to have accidentally happen is every single file in the folder have 1 subtracted from it. Only the files in the group I specify. I hope that makes sense. Can anyone help me with this?

User avatar
donj
Posts: 416
Joined: Thu Nov 16, 2006 9:02 pm

Renaming a bunch of files

Post by donj » Wed May 07, 2008 11:47 pm

So, if strFilename is the filename:

strExt = Right(strFilename,2)

Will put the last two digits of the filename extension into strExt. Then

intExt = CInt(strExt)

Will convert those two digits to a number, stored in intExt. You can then perform math with intExt.

User avatar
jimbo101974
Posts: 40
Joined: Wed Oct 31, 2007 11:01 pm

Renaming a bunch of files

Post by jimbo101974 » Thu May 08, 2008 12:00 am

Ok that makes sense. Can I also ask you this? If I want to strip off the file extension and use just the file name sans the extension in another part of the script how would I go about that?

User avatar
donj
Posts: 416
Joined: Thu Nov 16, 2006 9:02 pm

Renaming a bunch of files

Post by donj » Thu May 08, 2008 5:04 am

strJustFile = left(strFilename, Len(strFilename)-4)

That is, take the leftmost characters. How many of them? However many characters are in the string, minus 4 - which would be the period and the three-character filename extension.

Locked