Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: shortest command to find if a directory exists  (Read 2064 times)

0 Members and 1 Guest are viewing this topic.

stoneroses

  • Guest
shortest command to find if a directory exists
« on: July 03, 2006, 08:40:33 PM »
I would like to do this so that I can

if exists Dir then echo don't do anything
if not exists dir mkdir c:\thenewdirectory

-----------------------
My current solution is the following.Any suggestion for something shorter?

dir c:\thenewdirectory\ /s >> c:\patches.txt

if exists c:\patches.txt  echo don't do anything
if not exists c:\patches.txt mkdir c:\thenewdirectory


GuruGary



    Adviser
    Re: shortest command to find if a directory exists
    « Reply #1 on: July 03, 2006, 11:17:19 PM »
    This is the shortest solution I can think of based on your example:
    Code: [Select]
    if not exist c:\thenewdirectory md c:\thenewdirectory
    But you could always just use the MD command which will create the directory unless it already exists like this:
    Code: [Select]
    md c:\thenewdirectory>NUL