Link to home
Start Free TrialLog in
Avatar of Brent387
Brent387Flag for United States of America

asked on

Problem with batch command

I am learning batch scripting and am playing around with it. For some reason, this code makes three folders on my desktop titled "and" "data" and "settings." This is the code:

echo off
rem This file will create the PacePatches folder.  Each time a system is patched using logon scripts,
rem a .txt file will be placed in the folder confirming the successful patch deployment and
rem preventing repetitive installations
IF EXIST c:\%allusersprofile%\application data\Paceinstalls\* (Goto Found) ELSE (Goto NotFound)
:NotFound
rem now creating folder
md %allusersprofile%\appdata\PacePatches
:Found

What do I need to change?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
But in this case I think it is also because %alluserprofiles% i the full drive spec so does not need c:\, i.e.

echo off
rem This file will create the PacePatches folder.  Each time a system is patched using logon scripts,
rem a .txt file will be placed in the folder confirming the successful patch deployment and
rem preventing repetitive installations
IF EXIST "%allusersprofile%\application data\Paceinstalls\*" (Goto Found) ELSE (Goto NotFound)
:NotFound
rem now creating folder
md "%allusersprofile%\appdata\PacePatches"
:Found
Type just

set

on it's own at the cmd.exe prompt to see all the variables and their values.

Steve
Avatar of Bill Prew
Bill Prew

Yes, but no harm in quoting something that didn't need it, safer that way than assuming (eek, hate that word) that a path doesn't contain a space...

~bp
Bill, sorry I wasn't saying it didn't need quotes .. it certainly DOES like you say BUT he has added c:\ in front of %alluserprofiles% above which is what I meant was also breaking it ...
Of course it could be done more easily with just:

IF NOT EXIST "%allusersprofile%\application data\Paceinstalls\*" md "%allusersprofile%\appdata\PacePatches"

but there may be other reasons for doing it like it is.
Gotcha Steve, sorry for the misunderstanding...

~bp