Page 1 of 1

string operation. thx

Posted: 27 Jul 2010 03:49
by NicoNico
Hallo everybody,
iam at work and i need you to help me fast. I need a string operation.

Input ist a complete path:
example: C:/Test/Test/Test/Test.exe

The output should be only:
Test.exe

can somebody help me quickly?

Thanks a lot
Nico

Re: string operation. thx

Posted: 27 Jul 2010 06:13
by !k

Code: Select all

%comspec% /k for /?

Run & read.

Re: string operation. thx

Posted: 27 Jul 2010 06:37
by aGerman
!k is right, you should read the help of the FOR command.
In your case I would run a for /f loop

Code: Select all

@echo off &setlocal
set fullname=C:/Test/Test/Test/Test.exe
for /f "delims=" %%a in ("%fullname%") do set "name=%%~nxa"
echo %name%
pause

You will have the contents of %fullname% in %%a. In %%~nxa the n is for file name and the x is for file extension.

Regards
aGerman