1

i have an array and a variable

SET users=nick_derus peter_parker john_simpsons cool_guy
set mid=freak

i need to create files named like the following:

"derus freak nick"
"parker freak peter"
"simpsons freak john"
"freak guy cool"

and i'm failing over and over again. any help on how to do it?

2
  • What have you tried so far? I cannot see any nested loops in your "code"... Commented Sep 6, 2016 at 10:59
  • 1
    Just a comment: the SET users=nick_derus peter_parker john_simpsons cool_guy variable is not an array, but a list. Commented Sep 6, 2016 at 15:31

1 Answer 1

3

As they are unlikely file names, you'll have to determine the command you want to run yourself and change line five accordingly:

@Echo Off
Set users=nick_derus peter_parker john_simpsons cool_guy
Set mid=freak
For %%a In (%users%) Do For /F "Tokens=1* Delims=_" %%b In ("%%a") Do (
    Echo createfile "%%c %mid% %%b")
pause

This ignores the fact your last example name doesn't follow the format of the others.

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

1 Comment

Thanks a lot, last example was a mistake. It works great and it was much easier than what i was trying

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.