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.
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.
Why do you want that?
Johannes' answer is a possible solution, but maybe the path you refer to is being (or could be) passed as an argument to the script, in which case you can use the following syntax:
Alternatively you may combine
..
and the script path (%0
):Naïve substrings have the problem that you have to adjust them every time your paths change and it isn't a generic solution to the problem.
The following batch file gives a proof of concept how you might do the truncation part of the path:
It's hard-coded to a single variable but that is easily fixed if needed.
The core part here is the
strip
subroutine which loops and cuts off the last character of the string until a backslash is found. This effectively removes the last part of the path.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 forset
seems to contain most of the same information. (commandhelp set
)(Note: tested on Windows XP SP3)
Background:
Applied to problem: