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.
This topic is 15 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
jimbo101974
Posts: 40
Last visit: Mon Jan 12, 2009 4:52 am

Renaming a bunch of files

Post by jimbo101974 »

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
Last visit: Thu May 29, 2008 5:08 am

Renaming a bunch of files

Post by donj »

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
Last visit: Mon Jan 12, 2009 4:52 am

Renaming a bunch of files

Post by jimbo101974 »

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
Last visit: Thu May 29, 2008 5:08 am

Renaming a bunch of files

Post by donj »

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.
This topic is 15 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked