string operation. thx

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
NicoNico
Posts: 1
Joined: 27 Jul 2010 03:42

string operation. thx

#1 Post by NicoNico » 27 Jul 2010 03:49

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

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: string operation. thx

#2 Post by !k » 27 Jul 2010 06:13

Code: Select all

%comspec% /k for /?

Run & read.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: string operation. thx

#3 Post by aGerman » 27 Jul 2010 06:37

!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

Post Reply