0

im trying to split the strings. please find the details below,

Scenario:

set test1=“C:A\B\C\D\X\Y\Z”
set test2=“D:A\B\X\Y\Z”

echo %test1%
echo %test2%

i have to eliminate “\X\Y\Z” and i need the remaining string. expectation is it should print like below output

echo C:A\B\C\D
echo D:A\B

Thanks for reading this

Riv
  • 11
  • 3
  • First read the answer on [Why is no string output with 'echo %var%' after using 'set var = text' on command line?](https://stackoverflow.com/a/26388460/3074564) to understand how to define an environment variable right. And don't use `“` or `”`, just `"` which makes a big difference. Then run in a command prompt window `set /?` and read the help output into the window on several pages. You can read about string substitution. For your examples `echo %test1:\X\Y\Z=%` and `echo %test2:\X\Y\Z=%` produce the wanted output. – Mofi Dec 09 '17 at 17:40

1 Answers1

1

In case you don't want to remove a known string, but want the folder name "three up":

set "test1=C:\A\B\C\D\X\Y\Z"
for %%a in ("%test1%\..\..\..") do echo %%~fa
Stephan
  • 47,723
  • 10
  • 50
  • 81