1

I want to split the name of each folder (in a for loop) into 2 parts : the left part (before the delimiter " - ") and the right part (after the delimiter).

Example : "Bonjour - Cher ami" => left=Bonjour, right=Cher Ami

But it doesn't work :

for /d %%a in (*) do (
  set "fname=%%a" 
  set "right=%fname:* - =%" 
  call set "left=%%fname: - %right%=%%" 
  echo [%left%] * [%right%]
)

Thanks in advance

1
  • 1
    Do you want to read folder names and split the names and print them? Commented Mar 28, 2013 at 23:13

1 Answer 1

1

Inside a code block you need an other syntax:

@echo off &setlocal
for /d %%a in (*) do (
    set "fname=%%~a"
    call set "right=%%fname:* - =%%" 
    call call set "left=%%%%fname: - %%right%%=%%%%"
    call echo [%%left%%] * [%%right%%]
)

If there is no "-" in the folder name, then %left%==%right%.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! It works now, except that if %%a = blabla - hehe, then left=blablahehe right=hehe, instead of left=blabla right=hehe
Yes, you are right, code needs more %%. Will make an (hopefully last) edit :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.