Problem with batch command

Brent387
Brent387 used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Test your restores, not your backups...
Top Expert 2016
Commented:
Anytime a filepath can (or could) contain spaces you need to enclose that path in double quotes.  Otherwise the command processor things the spaces are seperateors between parameters.  So in your case:

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

~bp

Commented:
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

Commented:
Type just

set

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

Steve
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Bill PrewTest your restores, not your backups...
Top Expert 2016

Commented:
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

Commented:
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 ...

Commented:
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.
Bill PrewTest your restores, not your backups...
Top Expert 2016

Commented:
Gotcha Steve, sorry for the misunderstanding...

~bp

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial