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=%CDIR:~0,-24%

Open in new window

deleydSoftware EngineerAsked:
Who is Participating?

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

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:

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).

This sets the variable LIST = to the leftmost 32 characters of CDIR.

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
REM Remove the rightmost 24 characters of CDIR
SET CDIR=%CDIR:~0,-24%
REM Get just the leftmost 32 characters of CDIR
REM Get just the rightmost 6 characters of LIST

Open in new window

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

Open in new window

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

%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

%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

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.