1.

Solve : how to know the file name?

Answer» HI All,
I'm trying to RETRIEVE the file name of my batch file inside the file itself. I know that %0% contains the file that I run, but I would like to remove the directory INFORMATION.
I mean, if I have a test.bat file under c:\test and I run c:\test\test.bat .... %0% contains c:\test\test.bat instead of just "test.bat".
I'm looking for something like basedir in linux..

Any hint ?
Thanks a lot
Stenichele, you typed too many percent signs.

The variable that contains a batch file's path, name, and extension is %0 not %0%.

You can use some of the STANDARD variable modifiers on the %0 variable to get the bare filename and extension.

For full details of all the modifiers type FOR /? at the prompt

Consider an (imaginary) batch file C:\Test Files\Batch\mybatch.bat

Drive C:
Path \Test Files\Batch\
name mybatch
extension .bat

%0 gives the full path, file name, and extension C:\Test Files\Batch\mybatch.bat
%~n0 gives the name mybatch
%~x0 gives the extension including the DOT .bat

You can combine them so

%~nx0 gives the filename and the extension only (no drive or path) mybatch.bat

Actually you can build up the same result as %0 from parts as %~dpnx0 (drive, path, name, extension)

Hi contrex,
thanks a lot !!

ste


Discussion

No Comment Found