1.

Solve : ms-dos shorthand command help needed?

Answer»

Can someone point me to MS-DOS documentation that explains what is happening on LINE 5? Kind of hard to search for ":~" and find anything helpful.

for /f "tokens=1-4 delims=/ " %%a in ('DATE/T') do set MDATE=%%c%%a%%b
for /f "tokens=1-4 delims=/ " %%a in ('DATE/T') do set MM=%%a
for /f "tokens=1-4 delims=/ " %%a in ('DATE/T') do set DD=%%b
for /f "tokens=1-4 delims=/ " %%a in ('DATE/T') do set YY=%%c
IF %MM:~0,1%==0 SET MM=%MM:~1%
IF %DD:~0,1%==0 SET DD=%DD:~1%
set cdate=%MM%-%DD%-%YY%you can find info on this is you type set /? in a cmd window.


%PATH:~10,5%

would expand the PATH environment variable, and then use only the 5
characters that begin at the 11TH (offset 10) character of the expanded
result. If the length is not specified, then it defaults to the
remainder of the variable value. If either number (offset or length) is
negative, then the number used is the length of the environment variable
value added to the offset or length specified.

%PATH:~-10%

would extract the last 10 characters of the PATH variable.

%PATH:~0,-2%

would extract all but the last 2 characters of the PATH variable.



so in your case the line in question is saying if the first character of the variable %MM% is equal to 0 then set %MM% to the second character only.

This is useful if you are doing math because batch interprets a leading zero to be a octal number. Quote from: fossowat on October 16, 2009, 01:32:02 PM

Can someone point me to MS-DOS documentation

(1) This is not "MS-DOS". It is WINDOWS NT family command script. Specifically Windows 2000 and later.

(2) set /?

(part)

CODE: [Select]...specify substrings for an expansion.

%PATH:~10,5%

would expand the PATH environment variable, and then use only the 5
characters that begin at the 11th (offset 10) character of the expanded
result.


Discussion

No Comment Found