Easy batch command? if..

Mr Bob

Golden Member
Sep 6, 2004
1,757
12
81
Here's the logic of what I'm trying to do...

IF Folder Exists "C:\Program Files\Test\"
Do
:: some commands here
ELSE
Do
:: some commands here

Is there a way to check if a folder exists, and then if it does, run a program within that folder?
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,836
4,815
75
You can't technically check if a folder exists in DOS/Windows, but you can check if a file exists.

Code:
IF EXIST "c:\Program Files\Test\executable.exe" GOTO runexe
Rem Else code goes here
GOTO exedone
:runexe
Rem code to run the program goes here
:exedone

If you want them in the order you specified, use IF NOT EXIST. (Capitalization doesn't matter either; I just used it for emPHAsis. ;))
 

Snapshot1

Member
Dec 26, 2011
42
0
0
On Windows 7 Ultimate and XP Pro the following works using IF EXIST with respect to directories:
Code:
if exist "C:\Windows" (echo yes) else (echo no)
Snapshot1