Append extension name to filename

I need help with a vbscript.. basically what i need to do is append whatever the extension is to the end of the file name ...see below

before: george martin.epub
after: george martin (epub).epub

i have no clue as to how to go about it...any ideas?

If you don't know how to do it - why do you feel the need to do it in vbscript? You can do it with a regular Opus rename:


Because it needs to work in conjunction with the titlecase plus script that i heavily modified... i'm calling it book case now...its for cleaning large collections of books... one of the things some collectors like is to relabel the file type at the end of the file in brackets... but when your downloading collections a lot of times there is all this other junk in brackets that not necessary that can be stripped away leaving just the author - series # - title (version number) so i want there to be a choice to add back in the file type in brackets at the end of the file name a a dim choice in the script. If you want to see what i have done i've attached the script as a text file..its meant to be a button..it all ready works very good.. i'm theres ways to streamline what i have done i'm not a pro coder.

anyway i need it to be in vbscript to go along with the rest.... thank you for shwoing me how to do it the direct way though i wasn't sure about how to do it that way either.
BookCase.txt (150 KB)

If you look near the top of the script, one of the first things it does is remove the file extension and store it in the strExt variable, so that it can be put back on the filename right at the end (without being affected by the rest of the script).

So, since your script is based on Titlecase, you already have the extension and can simply insert it into the filename.

Thanks for the reply Leo... i figured it could be done. I just can't figure out what the commnands are to do it...i'm more a copy paste tweek kinda guy. I have to find an example first then copy it to mine i just haven't been able to find one. Could you possibly show me how if its not to much trouble

There's an example in the Rename forum post which shows how to use Jscrip, VBscript, PerlScript:

Thanks for your reply MRc but it doesn't give an example of whats in question

I figured out how to add in the extension name in with brackets around it but i can't figure out how to loose the period because i dont quite understand how it grabbed or not grabbed?

	'Strip the filename extension for now
	if fIsFolder = False then
		if InStr(strNewName, ".") then
			strExt = Right(strNewName, Len(strNewName)-(InStrRev(strNewName, ".")-1))
			strNewName = Left(strNewName, InStrRev(strNewName, ".")-1)

			' Convert extension to lowercase while we're at it
			if fExtLCase = True then
				strExt = LCase(strExt)
			end if
			
		else
			strExt = ""
		end if
	end if

	
	'Rejoin the name and extension and we're finished
	 strNewName = strNewName & " (" & strExt & ")" & strExt

Its doing this:

judgejudy.jpg ---> judgejudy (.jpg).jpg

how do i get it to look like this

judgejudy.jpg ---> judgejudy (jpg).jpg

I think it does. It shows you how to concatenate two strings. The example under the vbscribt section shows how to combine a text string and a string contained in a variable. Just combine your variable, as leo mentioned above, and the variable or string you have.

Time to get yourself educated here. :slight_smile:

a basterdized way to get rid of the dot would be to run dots to spaces...Leo do you know of a more streamlined way?

Add this after the "convert extension to lowercase bit":

strExt = Right(strExt, Len(strExt) - 1)

thank you you just solved in 1 line i was using 15 lines of code to do...cheers