Page 1 of 1

Renaming a bunch of files

Posted: Wed May 07, 2008 10:13 pm
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.


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?

Renaming a bunch of files

Posted: Wed May 07, 2008 11:47 pm
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.

Renaming a bunch of files

Posted: Thu May 08, 2008 12:00 am
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?

Renaming a bunch of files

Posted: Thu May 08, 2008 5:04 am
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.