Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

substring using bat command

I have the following thing in my bat file. say

set path=c:\temp\test

so basically i want to have an output which would give me the result as c:\temp\

i didnt find any indexof equivalent in bat command.

Thanks.

like image 516
user320550 Avatar asked Apr 22 '10 11:04

user320550


2 Answers

Background:

>set fullname=c:\mypath\oldfile
>set changedname=%fullname:oldfile=newfile%
>echo %changedname%
c:\mypath\newfile

Applied to problem:

> set fullname=c:\mypath\oldfile
> set pathonly=%fullname:oldfile=%
> echo %pathonly%
c:\mypath\
like image 122
Joachim Lous Avatar answered Sep 25 '22 08:09

Joachim Lous


A question that really makes me wish 4DOS still existed. However, I found something that might help in alt.msdos.batch.nt. The manual page for set seems to contain most of the same information. (command help set)

set test=123456789

rem extract chars 0-5 from the variable test
set test=%test:~0,5%

echo %test%

(Note: tested on Windows XP SP3)

like image 31
nikc.org Avatar answered Sep 25 '22 08:09

nikc.org