split a string in DOS

June 10, 2009 at 05:29:42
Specs: Windows XP
Hi
I have a path string like c:\xxx\yyy\zzz and I need to get the part of the path before one of the folder for example "yyy" (that is i have to use yyy like a delimiter in splitting the string).
Is it possible to do this in DOS?
Thanks
Sil

See More: split a string in DOS

Report •


#1
June 10, 2009 at 05:41:58
yes, you use a for loop, setting the delims parameters and tokens. see for /? for more info.

for myself, i prefer not using DOS. Here's one example in Python(for windows) that makes things easier

path=r"c:\xxx\yyy\zzz"
print path.split("\\")[2]

output
c:\test> python test.py
yyy


Report •

#2
June 10, 2009 at 05:55:02
There's no delims in DOS, folks.


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#3
June 10, 2009 at 08:42:53
I assume OP is using XP as judging from his/her profile, therefore its cmd.exe

Report •

Related Solutions

#4
June 17, 2009 at 03:25:26
thanks for your answers.
But I have to split the using a folder name as delim and not the slash (without knowledge of the level of this folder), and in DOS this seems to be not possible.
If you have any other idea..
Thank you

Report •

#5
June 17, 2009 at 08:54:48
If you're looking for the name of the parent directory, then that's not too hard.
for %a in (c:\xxx\yyy\zzz\..) do @echo %~Na


Report •

#6
June 18, 2009 at 00:32:07
this can help.
Thanks a lot

Report •


Ask Question