Batch Processing All Executable Files in a Folder
This sample code provides a real-world example that demonstrates many of the features available in Resource Tuner Console. This code shows how to batch process the contents of a directory.
The script scans the specified Source directory for all files available. Then, for each file with given file extension (EXE, DLL, SYS, CPL) it calls for the ProcessFile procedure to set the English-US language for all of the resources in the file and update the Version Information. The resulted files are saved to the Destination directory.
'------------------------------------------------------------------------------ ' ' This code shows how to batch process the contents of a directory. ' It processes specific file extensions (EXE, DLL, SYS, CPL) in the source directory. ' '------------------------------------------------------------------------------ '---------------------------------------------------------------------------- ' ProcessFile ' ' Purpose: ' ' Processes a file: it sets the English-US language for all of the resources ' in the file, and modifies/adds a Version Information resource. '---------------------------------------------------------------------------- Sub ProcessFile (Src_Path, Dest_Path, File_Name) LangID = 1033 ' English-US CP = ScriptUnit.CodePageFromLangID(LangID) PEFileProxy.OpenFile Src_Path & File_Name If Not PEFileProxy.Terminated Then If PEFileProxy.HasResources Then ResourcesProxy.SetLanguage LangID, DELETE_IF_EXISTS If ResourcesProxy.OpenVersionInfo("1", LangID, CREATE_IF_NOT_EXIST) Then VersionInfoProxy.SetFileVersion 2, 0, 1, 122, LangID, True, True, True VersionInfoProxy.SetProductVersion 2, 0, 0, 0, LangID, True, True, True S1 = "Copyright \0xA9 2023 SuperSoftware Development" S2 = "SuperProg is a trademark of SuperSoftware Development" S3 = "This file modified by Resource Tuner Console" VersionInfoProxy.EditStringFileInfo "LegalCopyright", S1, CP, LangID, True, True VersionInfoProxy.EditStringFileInfo "LegalTrademarks", S2, CP, LangID, True, True VersionInfoProxy.EditStringFileInfo "Comments", S3, 1049, LangID, True, True ResourcesProxy.CloseVersionInfo PEFileProxy.Compile PEFileProxy.SaveAsNewImage Dest_Path & File_Name Else PEFileProxy.PostDebugString "Failed to open/create Version Info..." End If End If End If End Sub '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ' The main routine. ' ' First, it scans the specified Source folder for files available. ' Then, for each file found it calls for the ProcessFile procedure. ' '------------------------------------------------------------------------------ Sub Main dim Src_Path, Dest_Path, File_System_Object, Folder_Object, File_Object, File_Collection PEFileProxy.UpdateCheckSum = True PEFileProxy.CreateBackUp = False ' Specify the path to the Source Folder Src_Path = ScriptUnit.CurrentFolder & "src\" ' Specify the path to the Destination Folder Dest_Path = ScriptUnit.CurrentFolder & "release\" ' Scan the specified folder, and then process all files found. set File_System_Object = CreateObject("Scripting.FileSystemObject") set Folder_Object = File_System_Object.GetFolder(src_path) set File_Collection = Folder_Object.Files for each File_Object in File_Collection ' Get an extension and modify it to one uniform lower case ' because there may be both upper and lower case characters FL_EXT = LCase(File_System_Object.GetExtensionName(File_Object.name)) ' Check an extension and process specific file extension If FL_EXT = "exe" or FL_EXT = "dll" or FL_EXT = "sys" or FL_EXT = "cpl" then ProcessFile Src_Path, Dest_Path, File_Object.name PEFileProxy.PostDebugString "*************************************" End If Next End Sub '------------------------------------------------------------------------------ |
To see the changes made to the test EXEs, we recommend using Resource Tuner GUI, a visual resource editor.
Once installed Resorce Tuner Console, you will find the Demo folder in the directory where RTC has been installed. Within this Demo folder, there are 11 subdirectories that contain sample scripts and sample executable files.
All sample scripts are ready to run. Select one of the .BAT files located in the Demo folders to execute the sample script. The script will make changes in the test EXE file. The resulting file will be created in the directory named "Release" under the directory containing the script.
Download Resource Tuner Console and learn how it can make you more productive.