Concept of the script have been refined over the years to allow rapid development in Batch Script. Right now, it is very likely that it is suitable for any batch script project.
Personally I have used this in lots of my scripts and it saved me a lot of time and stress (sometimes days of it). Hope this script would help someone save some time.
Features
- Easy to use, suitable for beginners
- Powerful, made for hardcore batch script users.
- Does not pollute global variables (otherwise specified in documentation)
- Highly reusable (some functions can even be pasted inside a loop without modifying logic of the function)
- Extensive documentation and demo
- Important functions have written unittest. Functionality can be tested before use.
- Can be used as standalone script (otherwise specified in documentation)
Calling batchlib functions from script:
Number Functions
There is a small note at the end of the script that might be useful...
- Copy text from script to clipboard automatically
- Detect if file is locked or not
- Create 0-byte file
- Encode/decode base64 and hex file
- And more...
Language: Windows Batch Script (.bat)
View source code here:
Batch Script Library (latest)
Scripts are now uploaded to GitHub to ensure it is easily reachable and stays available.
set batchlib="C:\path\to\batchlib.bat" -c call %=END=%
call %batchlib%:pow result 4 6
echo Result: %result%
call %batchlib%:pow result 4 6
echo Result: %result%
Number Functions
- Generate random number
- Select random choice according to choice weight
- Square root, cube root, y-root
- x to the power of y
- Primality test (Check whether a number is prime or not)
- GCF (Greatest Common Factor)
- Calculate string length
- To UPPERCASE, lowercase, Capital Case
- Strip surrounding double quotes
- Print strings formatted as tables
- Binary to integer, vice versa
- Integer to octal
- Integer to hexadecimal
- Integer to Roman numeral, vice versa
- Calculate time difference (in 1/100 seconds)
- Calculate date difference (in days). Can be used to calculate days since epoch.
- Calculate seconds since epoch from date and time and vice versa.
- Determine day of a given date (26 August 2017 is Saturday)
- Delay with millisecond accuracy
- Measure execution speed of a code (timeit)
- Find files and/or folders with wildcards (*) in path and wildcard drive letter
- Check if path entered is a file or folder, and whether it exist or not
- Unzip file
- Calculate checksum of file
- Check whether 2 file are the same. If not, return offset bytes of difference.
- Convert file to hex (line by line)
- Get external IP address
- Download file
- Expand url (seperate url to smaller piece of data)
- Get console size
- Check for administrator rights
- Get current user's SID
- Get OS version
- Get process ID (PID) of current script
- Monitor variable changes in a script
- Detect whether script uses Windows EOL (CRLF) or Unix EOL (LF)
- Make variables survive endlocal
- Capture special characters (backspace, escape, carriage return, line feed, ...)
- Convert hex color to ANSI escape sequence ( '02' -> '[40;32m' )
- Color print text
- Macro to clear text in current line
User interfaces
- Input number within specified range
- Input yes/no and set custom value for each choice
- Input file/folder with validation
- Input IPv4 with validation
Packaging
- Run batch script as module/library
- Extract function of a batch script
- Parse version into a form that can be used to compare versions
- Automatically update script from the internet
- Convert LF to CRLF (for scripts downloaded from GitHub)
- Automatic function dependency resolver for batch script
- Batch script templating
- Unit testing framework
- Parse arguments
- Keep variables after endlocal
There is a small note at the end of the script that might be useful...
- Copy text from script to clipboard automatically
- Detect if file is locked or not
- Create 0-byte file
- Encode/decode base64 and hex file
- And more...
Language: Windows Batch Script (.bat)
View source code here:
Batch Script Library (latest)
Scripts are now uploaded to GitHub to ensure it is easily reachable and stays available.
No comments:
Post a Comment