Reputation: 560
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
Upvotes: 0
Views: 1399
Reputation: 79982
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 CALL
ed :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)
Upvotes: 3