1.

Solve : Getting Characters from a Bat file name.?

Answer»

I am in TNCAAK1.BAT which has the command

call AAAAAA.BAT T AK


The first arguement to AAAAAA is the same as the first char of the BAT file TNCAAK1' s name while the second argument is is the 5th & 6th character of the name.

Does anyone know how to GET those arguments from the name?

Thank you







Quote from: zscipio on January 25, 2009, 07:04:52 PM

I am in TNCAAK1.BAT which has the command
call AAAAAA.BAT T AK
The first arguement to AAAAAA is the same as the first char of the BAT file TNCAAK1' s name while the second argument is is the 5th & 6th character of the name.
Does anyone know how to get those arguments from the name?

Code: [Select]@echo off

REM %0 CONTAINS a batch file's OWN NAME
REM USE ~n variable modifier to get name part
set myname=%~n0

REM use set shortstring=%longstring:~offset,length% string slicing to get chars
REM first char is offset 0
set p1=%myname:~0,1%
set p2=%myname:~4,2%

REM demonstration
echo full name + EXTENSION is %0
echo name part only is %myname%
echo the 1st character of name %p1%
echo 5th and 6th chars of name %p2%
REM delete when satisfied

REM call other batch file
call AAAAAA.BAT %p1% %p2%


Discussion

No Comment Found