Link to home
Start Free TrialLog in
Avatar of deleyd
deleydFlag for United States of America

asked on

What does this do? SET CDIR=%CDIR:~0,-24%

Lines in a DOS batch file (e.g. ABCDEFGHIJKLMNOP.BAT) What do these lines do?

The first line gets the name of the batch file itself.
Then what's all that rest do with the file name?
SET CDIR=%0
SET CDIR=%CDIR:~0,-24%
SET LIST=%CDIR:~0,32%
SET LIST=%LIST:~-6%

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of dsacker
dsacker
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Just to add.... if they are trying to get part of the filename the use of %0 depends upon what was actually used to RUN the batch file, e.g. using this batch file to show some of the operators to get the (d)rive, (p)ath, (f)ull path, (n)ame and e(x)tension parts.  So would suggest NOT using %0 but combinations of below:

@echo off
echo %%0 %0
echo %%~0 %~0
echo %%~dp0 %~dp0
echo %%~f0 %~f0
echo %%~nx0 %~nx0
pause

Open in new window


If it is run just using "1" from command prompt:

C:\Users\stephen>1
%0 1
%~0 1
%~dp0 C:\Users\stephen\
%~f0 C:\Users\stephen\1.cmd
%~nx0 1.cmd
Press any key to continue . . .

Open in new window


If it is run using c:\users\stephen\1.cmd

C:\Users\stephen>c:\users\stephen\1.cmd
%0 c:\users\stephen\1.cmd
%~0 c:\users\stephen\1.cmd
%~dp0 c:\Users\stephen\
%~f0 c:\Users\stephen\1.cmd
%~nx0 1.cmd
Press any key to continue . . .

Open in new window


Also if you do want (maybe?) the 6 characters from character 26 in the name then you can use:

set cdir=%~f0
%CDIR:~26,6%

Open in new window

Avatar of deleyd

ASKER

Thank you Steve for that information. It was very helpful. :)