Page 1 of 1

extracting file name from an environment variiable

Posted: 12 Oct 2009 17:03
by keneo
I know that you can parse complete file path names easily when expanding batch file parameters.

For example, you may execute the following command line:

PROCESS.BAT C:WINDOWS\NOTEPAD.EXE

where process.bat contains the following line:

@ECHO %~NX1

The results would be:

NOTEPAD.EXE


But is there a way to easily parse environment variables in a siimilar way? or a way to convert the environment variable into a parameter so I may use these file name parsing functions on it?

Posted: 12 Oct 2009 18:52
by ghostmachine4
show an example of that env var you want to parse and what you expect your final output to look like.

Posted: 13 Oct 2009 05:37
by keneo
Hi ghost,

ok, lets say I have the variable: %XXX% which contains:

c:\program files\some folder\program.exe

I would like the to extract just the file name from that:

program.exe

Posted: 14 Oct 2009 11:38
by avery_larry

Code: Select all

@echo off
set "testvar=c:\tmp\test.txt"
call :process %testvar%
goto :eof

:process
echo %~nx1
goto :eof