extracting file name from an environment variiable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
keneo
Posts: 5
Joined: 12 Oct 2009 16:50

extracting file name from an environment variiable

#1 Post by keneo » 12 Oct 2009 17:03

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?

ghostmachine4
Posts: 319
Joined: 12 May 2006 01:13

#2 Post by ghostmachine4 » 12 Oct 2009 18:52

show an example of that env var you want to parse and what you expect your final output to look like.

keneo
Posts: 5
Joined: 12 Oct 2009 16:50

#3 Post by keneo » 13 Oct 2009 05:37

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

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#4 Post by avery_larry » 14 Oct 2009 11:38

Code: Select all

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

:process
echo %~nx1
goto :eof

Post Reply