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

deleydSoftware EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dsackerContract ERP Admin/ConsultantCommented:
SET CDIR=%0

This is the easy one. It sets CDIR = to the .bat file that is running.
SET CDIR=%CDIR:~0,-24%

This chops off the rightmost 24 characters (a negative number goes from the right).
SET LIST=%CDIR:~0,32%

This sets the variable LIST = to the leftmost 32 characters of CDIR.
SET LIST=%LIST:~-6%

This sets LIST = to the rightmost 6 characters only.
That must one long bat file name. My guess is that it is fixed width and that those particular character positions mean something within the company.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bill PrewIT / Software Engineering ConsultantCommented:
Comments below.

REM Get full pathname of this BAT file
SET CDIR=%0
REM Remove the rightmost 24 characters of CDIR
SET CDIR=%CDIR:~0,-24%
REM Get just the leftmost 32 characters of CDIR
SET LIST=%CDIR:~0,32%
REM Get just the rightmost 6 characters of LIST
SET LIST=%LIST:~-6%

Open in new window

~bp
Steve KnightIT ConsultancyCommented:
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

deleydSoftware EngineerAuthor Commented:
Thank you Steve for that information. It was very helpful. :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft DOS

From novice to tech pro — start learning today.