0

I cant figure out this variable scope.. heres the code. I've been reading around but cant seem to nail it. I want to copy a file 4 times and concatenate a name every time expanding the name of the file. it will copy: Cow, Cow Cow, Cow Cow Cow, etc.

set "hash = Cow"
call:filecreate "Cow","%hash%"

:filecreate
set "name = %~1"
for /l %%C in (1,1,4) do (
for /f %%a in ('xcopy "%filez%" "%desktop%" /H /Y /R /F') do (
ren "%desktop%\system.ini" "!name!"
)
set "name = !name! %~2"
)
goto:eof

1 Answer 1

3

SPACES are significant in SET statements.

set var = something

will set a variable "var " to " something"

set var=something

will set a variable "var" to "something"

(also beware - having CALLed :filecreate, batch wil then execute :filecreate a second time because it does NOT recognise a label as 'end of procedure'. You need an explicit GOTO :EOF after the CALL if you only want the procedure to be executed once)

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

Comments

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.