Batch Rename .EXE Advanced Scripting Reference
by: unknown -
Batch Rename .EXE Product Info and Download Page
Use this page as a reference for variables and basic VB Script functions.
This tutorial will teach you how to:
1. What variables are available to use.
2. Basic reference for VB Scripting commands.
Reference (Built-in Variables):
The following variables allow you read and modify the file.
For the file c:\photos\Example Photo.jpg
| strFileName |
'Gets of sets the filename 'example photo' |
| strExtension |
'Gets or Sets the file extension 'jpg' |
| strPath |
'Gets of sets the path of the file. 'c:\photos\' |
| Number |
'Gets or Modifies the current file number. Example: If you a running a batch rename on 20 files, number would start at 1 for the first file, then 2, then 3 and so on, up to 20. |
Number = Number + 9 'set the start number at 10
strFilename = "New " & Number 'Set filename to new #
strExtension = ".jpeg" 'set extension to '.jpeg'
strPath = strPath & strExtension & "\" |
The above code would rename our file:
c:\photos\Example Photo.jpg > c:\photos\.jpeg\New 10.jpeg
c:\photos\Example Photo 2.jpg > c:\photos\.jpeg\New 11.jpeg
c:\photos\Wow A Photo.jpg > c:\photos\.jpeg\New 12.jpeg
Reference (VB Script Functions):
Use the following functions to manipulate the filename to your needs.
Replace:
| Replace |
'Replace's one string with another.
replace(Original String, Find String, Replace String) |
strFileName = Replace(strFileName, "Example ", "New ") |
Replace 'Example ' with 'New ' in the filename.
c:\photos\Example Photo.jpg > c:\photos\New Photo.jpg
strFileName = Replace(strFileName, "The ", "") |
Removes the word 'The ' from the filename
c:\photos\The Example The Photo.jpg > c:\photos\Example Photo.jpg
Lower Case:
| LCase |
''Converts the string to lower case. No capitals.
lcase(string) |
strExtension = Lcase(strExtension) |
c:\photos\Example Photo.JPG > c:\photos\Example Photo.jpg
Upper Case:
| UCase |
''Converts the string to lower case. All capitals.
ucase(string) |
strFileName = Ucase(strFileName) |
c:\photos\Example Photo.jpg > c:\photos\EXAMPLE PHOTO.jpg
Left:
| Left |
''Gets x chars starting from the left.
left(string,number of chars) |
strFileName = Left(strFileName,4) |
c:\photos\Example Photo.jpg > c:\photos\Exam.jpg
Right:
| Right |
''Gets x chars starting from the right.
right(string,number of chars) |
strFileName = right(strFileName,5) |
c:\photos\Example Photo.jpg > c:\photos\Photo.jpg
Text Length:
| Len |
''Gets number of chars in a string
len(string) |
strFileName = strFileName & len(strExtension) |
In the first, case len would return 4, because the extension is '.jpg'.
c:\photos\Example Photo.jpg > c:\photos\Example Photo4.jpg
In the second case len would return 5 because the extension is '.jpeg'
c:\photos\Example Photo.jpeg > c:\photos\Example Photo5.jpeg
Find In String :
| InStr |
''Find where a string is. (Note: If the return number is < 0 then the string is not in the text.)
InStr(Start,String, Find String) |
strFileName = left(strFileName,InStr(1,strFilename," Photo") + 1) |
Get the position where ' Photo' Starts then trims using Left to that position.
c:\photos\Example Photo.jpg > c:\photos\Example.jpg
Split String :
| Split |
''Get a part of the string
split(string, split by) (part) |
strFileName = split(strFileName, " ")(1) |
Split the filename by it's spaces and return the second value.
c:\photos\Example Photo.jpg > c:\photos\Photo.jpg
strFileName = split(strFileName, " Photo")(0) |
Split the filename by the word ' Photo' and return the first value.
c:\photos\Example Photo.jpg > c:\photos\Example.jpg
If.. Then.. Else (Conditional Formatting) :
| If Statement |
''If something then do, else do
If (con) =,<>,>,< (con) Then
Else
End if |
If lcase(strExtension) = ".gif" then
strFileName = strFileName & " (This is a Compu GIF Image)"
ElseIf
lcase(strExtension) <> ".jpg" then
strFileName = ucase(strFileName)
else
strFileName = strFileName & " (This is a JPEG Image)"
End If |
If the lcase case of the files extension is '.gif' then add the text '(This is a Compu GIF Image)' image to the filename, otherwise if the extension is anything but ".jpg" then convert the filename to upper case, otherwise it must have been a ".jpg" and mark the filename with '(This is a JPEG Image)'
c:\photos\Example Photo.gif > c:\photos\Example Photo (This is a Compu GIF Image).gif
c:\photos\Example Photo.bmp > c:\photos\EXAMPLE PHOTO.bmp
c:\photos\Example Photo.jpg > c:\photos\Example Photo (This is a JPEG Image).jpg
Reference (Examples):
These are examples of things that can be done.
Place each file in a folder of it's file type:
'If a JPEG image is in short form (.jpg), Put in JPEG Folder.
if lcase(strExtension) = ".jpg" then
strPath = strPath & "JPEG\"
else
strPath = strPath & ucase(replace(strExtension, ".", "")) & "\"
end if |
c:\photos\Example Photo.jpg > c:\photos\JPEG\Example Photo.jpg
c:\photos\Example Photo.gif > c:\photos\GIF\Example Photo.gif
c:\photos\Example Photo.bmp > c:\photos\BMP\Example Photo.bmp
c:\photos\Example Photo 2.jpg > c:\photos\JPEG\Example Photo 2.jpg
Advanced Functions and Code For Music Renaming in Folders :
Main Code:
strFilename = GetArtist(strPath) & " - " & _
Trim(GetAlbum(strPath)) & " - " & strFilename |
My Functions Code:
Function GetAlbum(strMyPath)
dim sRet
sRet = split(strMyPath, " - ")(1)
If inStr(1,sRet,"(") then
sRet = split(sRet,"(")(0)
end if
GetAlbum = sRet
End Function
Function GetArtist(strMyPath)
dim sRet
sRet = split(strMyPath, " - ")(0)
If inStr(1,sRet,"(") then
sRet = split(sRet,"(")(0)
end if
GetArtist = sRet
End Function |
Download the BRS script file for the above. (Save, then use open in BR .EXE script editor)
c:\The WizBanks - Extraordinary Night (Retail)\01 - Version Of Night.mp3
> into >
c:\The WizBanks - Extraordinary Night (Retail)\The WizBanks - Extraordinary Night - 01 - Version Of Night.mp3
<< You have reached the end of this tutorial >> |