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.

4
  • 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
    Sep 19, 2015 at 8:00
  • For example, IF exist var1(brk_file) (with or without the asterisks) doesn't look like something that matches the IF command syntax.
    – zagrimsan
    Sep 19, 2015 at 8:04
  • Adding the %Var1% has resolved it, thank you! I completely spaced the %. So now I am able to test that section and echo true. set /p var1="What is your Name?" cd C:\ProgramData\filepath\Users\ IF exist *%var1%*(brk_file) echo true
    – Cam
    Sep 19, 2015 at 16:44
  • What is (brk_file)? If it's a string and part of the var1, you have to escape ( and ) like ^(brk_file^) Or you could probably enclose in double quotes like IF exist "var1(brk_file)" but not sure. Anyway this kind of symbol in files path are never good.
    – Paul
    Sep 20, 2015 at 2:41

1 Answer 1

0

This is an XY problem. To solve Y, you create a second problem called X and so on. While it easier to ask whether there is not already a solution for Y.

Which is the case. This is called Environment Variable. In your case you are seeking for the user variable.

Type set in the cmd you will understand what I mean.

Then type @echo My username is: %USERNAME% and my home is: %USERPROFILE%.
which will return:

 My username is: John and my home is: C:\Users\John

Anyway many mistakes in your code. You have to read IF /? because ELSE statement have to be in the same line of IF unless you use ) then it should be written in one line like ) ELSE (

Another thing: What is (brk_file)?

If it's a string and part of the var1, you have to escape ( and ) like

IF exist %var1%^(brk_file^)

or may you could probably enclose in double quotes like

IF exist "%var1%(brk_file)"

but honestly I am not sure.
Anyway this kind of symbol in files path are never good

3
  • 1
    My need for this file was to repair voice files associated to Nuance. They "corrupt" in 2 ways. The first would be c:\ProgramData\Nuance\NaurallySpeaking*\Users\Camv10\current -folder craps out for some reason, which the fix is to delete "Current" and make a copy of the back up file and name it current.
    – Cam
    Sep 21, 2015 at 23:39
  • And the second is when Nuance goes to overwrite the backup folder with the current folder and fails for some reason. What it will do is Keep the existing working folder and add (DGN_RENAMED) so camv10(DGN_RENAMED) and then it will dump the the progress of the backup to a folder named camv10 in my case so you must delete the broken camv10 folder then rename the camv10(DGN_RENAMED back to just camv10. Both of these situations come up often, so here is what I cam up with
    – Cam
    Sep 21, 2015 at 23:39
  • SET/p var1="What is the providers name?"% CD c:\PrgmDta\Nuance\NatSpeaking*\Users\ IF EXIST *%var1%**(DGN_RENAMED) ( GOTO :Renamed) ELSE (GOTO :Repair) :Renamed CD c:\PrgrmDta\Nuance\NatSpeaking*\Users*%var1% for %%* in (.) do set var2=%%~nx* CD c:\ProgramData\Nuance\NaturallySpeaking*\Users**(DGN_RENAMED) for %% in (.) do set var3=%%~nx* CD c:\PrgrmData\Nuance\NatSpeaking*\Users\ RMDIR /S /Q %var2% SET var4=%Var3:~0,-13% rename %var3% %var4% GOTO eof :Repair CD c:\PrgrmDta\Nuance\NatSpeaking*\Users*%var1%* REN "current" "current.old" ROBOCOPY "backup" "current" /e
    – Cam
    Sep 21, 2015 at 23:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .