1
1
What I am attempting to do is automate some work I do daily. What I would like to happen is a prompt saying What is your name? Then use that answer as a variable to be used in different commands like REN and ROBOCOPY. I am currently doing the following.
set /p var1="What is your Name?"
cd C:\ProgramData\filepath\Users\
IF exist var1(brk_file) (
gotto :renamed)
else
(goto :repair)
:Repair
REN "var1\current" "current.old"
ROBOCOPY "var1\backup" "current" /e
Now, their name will always be used in the folder name, but it could include a version number or MD or something else. For instance my answer would be "Cam" but my folder I am wanting to rename and copy is "CamV10"
So I would like something like
if exist *var1*(brk_file) (
goto :renamed)
else
(goto :repair)
:repair
REN "*var1*\current" "current.old"
ROBOCOPY "*var1*\backup" "current" /e
This is not working for me, any suggestions would be appreciated.
If
var1
in your post is supposed to be the variable, it should be surrounded by percent-signs:%var1%
and not with asterisks. But the code is a bit unclear and has other typos, too, so please do edit the question with the actual code that works (can be executed without errors). – zagrimsan – 2015-09-19T08:00:57.657For example,
– zagrimsan – 2015-09-19T08:04:28.543IF exist var1(brk_file)
(with or without the asterisks) doesn't look like something that matches theIF
command syntax.Adding the %Var1% has resolved it, thank you! I completely spaced the %. So now I am able to test that section and echo true.
What is
(brk_file)
? If it's a string and part of thevar1
, you have to escape(
and)
like ^(brk_file^) Or you could probably enclose in double quotes likeIF exist "var1(brk_file)"
but not sure. Anyway this kind of symbol in files path are never good. – Paul – 2015-09-20T02:41:29.307