Difference between revisions of "Windows Batch Script"

From PKC
Jump to navigation Jump to search
(Created page with "Windows Batch Script is a crucial instrument for setting up PKC on Windows 10 platform. =Useful Websites= # https://www.tutorialspoint.com/batch_script/index.htm")
 
 
(9 intermediate revisions by the same user not shown)
Line 2: Line 2:


=Useful Websites=
=Useful Websites=
# https://www.tutorialspoint.com/batch_script/index.htm
# [https://www.tutorialspoint.com/batch_script/index.htm Batch Script Tutorial] on [https://www.tutorialspoint.com Tutorial Point]
# [https://kedar.nitty-witty.com/blog/bat-batch-file-to-create-formatted-date-ddmmyyyy-directory Batch File to Create Formatted Date and Time]
# [http://www.trytoprogram.com/batch-file/ Batch File Programming]
 
==Useful Hints==
The following special expressions or characters may be useful in understanding Batch Script:
=== SET /A===
SET varibale_name=variable_value
:: for assigning numeric value
SET /A variable_name=nameric_value
‘/A’ is used for assigning numeric values. Uninitialized variables are empty strings in batch files.
 
=== FOR /L===
FOR /L %%var_name IN (Lowerlimit, Increment, Upperlimit) Do some_code
*‘/L’  signifies that for loop is used for iterating through a range of integer values.
*Lower limit is the value from which loop will start until it reaches the Upper limit and the increment is the value with which lower limit will be increased during each iteration
 
===Formatting Date and Time===
@echo off
set yy=%date:~-4%
set mm=%date:~-7,2%
set dd=%date:~-10,2%
set MYDATE=%yy%%mm%%dd%
For using delimiters, try the following:
for /f “tokens=2-4 delims=/ ” %%g in (‘date /t’) do (
set mm=%%h
set dd=%%g
set yy=%%i
)
set MYDATE=%yy%%mm%%dd%

Latest revision as of 13:51, 18 August 2021

Windows Batch Script is a crucial instrument for setting up PKC on Windows 10 platform.

Useful Websites

  1. Batch Script Tutorial on Tutorial Point
  2. Batch File to Create Formatted Date and Time
  3. Batch File Programming

Useful Hints

The following special expressions or characters may be useful in understanding Batch Script:

SET /A

SET varibale_name=variable_value
:: for assigning numeric value
SET /A variable_name=nameric_value

‘/A’ is used for assigning numeric values. Uninitialized variables are empty strings in batch files.

FOR /L

FOR /L %%var_name IN (Lowerlimit, Increment, Upperlimit) Do some_code
  • ‘/L’ signifies that for loop is used for iterating through a range of integer values.
  • Lower limit is the value from which loop will start until it reaches the Upper limit and the increment is the value with which lower limit will be increased during each iteration

Formatting Date and Time

@echo off
set yy=%date:~-4%
set mm=%date:~-7,2%
set dd=%date:~-10,2%
set MYDATE=%yy%%mm%%dd%

For using delimiters, try the following:

for /f “tokens=2-4 delims=/ ” %%g in (‘date /t’) do (
set mm=%%h
set dd=%%g
set yy=%%i
)
set MYDATE=%yy%%mm%%dd%