Last active
April 4, 2023 06:54
-
-
Save nivranaitsirhc/a75efdd3e976a38f7eb95ad44a235265 to your computer and use it in GitHub Desktop.
A batch script wrapper for portable apps or applications.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
REM --------------------------------------------------------------- | |
REM Batch Script Wrapper Caller for Portable Apps or Scripts (cmd) | |
REM --------------------------------------------------------------- | |
REM Author : cacc@greenleaflabworks | Christian Arvin C. Cabo | |
REM Date : 2023-01-07 | |
REM Paypal : @caccabo | |
REM GCash : 09276311928 | |
REM This is a wrapper for portable apps that updates to the same directory with a different app name. | |
REM A complete example is rufus portable. Just create a new directory and register this path to windows environment variable. | |
REM Create a rufus directory and place the rufus app inside. On the root directory rename this wrapper to rufus.cmd and configure the variables below. | |
REM | |
REM Example Setup | |
REM D:/user-bin -->| (D:/user-bin is the registered path) | |
REM /rufus.cmd | |
REM /rufus-portable -->| | |
REM /rufus-3.21.exe (this will be called) (rufus latest version) | |
REM /rufus-3.20.exe | |
REM /rufus-3.18.exe | |
REM /...(other files and directory) | |
:: --- Instructions Start --- | |
:: place this wrapper cmd outside the root directory you want to wrap | |
:: change the configuration variables to your needs | |
:: --- Instructions End --- | |
:: configuration variables | |
set target_dir=rufus-portable | |
set target_exe=rufus*.exe | |
:: constant variables | |
set working_dir=%~dp0 | |
:: --- code flow start --- | |
:: 1. save current caller directory | |
:: 2. create a local with enabled delayed expansion (not really needed but enabled for future uses) | |
:: 3. call the drive letter ** this is important if our app is on another drive ** | |
:: 4. cd to the directory using the configuration variables | |
:: 5. loop into the target directory and execute the first result ** /r is used as to select the current app, e.g. rufus-x-x.exe ** | |
:: Notes: inside the loop if our application has a GUI add a "start" command before the %%a %* | |
:: --- code flow end --- | |
:: #script start | |
pushd %cd% | |
setlocal ENABLEDELAYEDEXPANSION | |
%working_dir:~0,1%: | |
cd %working_dir%%target_dir% | |
for /f "usebackq delims=''" %%a in (`dir /b /a:-d /s %target_exe% ^| sort /r`) do ( | |
( | |
pushd %%~dpa | |
:: ------------------------------------------ | |
:: For console Apps use this without start | |
%%a %* | |
:: ------------------------------------------ | |
:: For GUI Apps use this | |
:: start %%a %* | |
popd | |
) & goto:exit | |
) | |
:exit | |
endlocal | |
popd | |
:: #script end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment