adealey
I know how to extract a file name extension from a parameter (%~x1) but is there some way to apply this function to an environment variable? I swear I've seen something somewhere about doing that but nothing I have tried has worked.
----------------------------
#2 13 Jul 2011 15:22
RG
Something like this will do it:
Code: Select all
@ECHO OFF
CALL :GetExt xxxx.bat
ECHO.%Ret%
pause
GOTO :eof
:GetExt
REM %1=FileName%
SET Ret=%~x1
SET Ret=%Ret:~1% & REM Only include this line if you want to get rid of the .
GOTO :eof
----------------------------
#3 13 Jul 2011 16:44
flabdablet
Closest thing I know of to a neat inline way to do this is using for:
Code: Select all
set file=C:\Program Files\Fubar\fubar.exe
for %%F in ("%file%") do echo Drive=%%~dF Path=%%~pF Name=%%~nF Ext=%%~xF