🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.misc
Article #3919

Re: How to know if a dir exists (Batch way)

#3919
From: John Savage
Date: Wed, 20 Dec 1995 00:00
32 lines
1926 bytes
In a recent article I wrote:

>>> Try     if exist d:\path\nul goto success
>>> to test for the existence of d:\path
>>
>>Unfortunately, this does NOT always work.  The problem involves having some
>>(usually network) drivers loaded in memory, which hinder the performance of

>A further way of determining the existence of a directory can be based
>on whether or not there is any output produced by DIR /B
>
>dir /B %1 >tmp1
>copy tmp1 tmp2 >\nul
>if not exist tmp2 echo DIRECTORY NOT FOUND
>
>This is based on DIR /B producing no output when a directory does not exist.

Yet another DOS method for determining the existence of a directory, though
I'd be surprised if it were found to work with read-only media:-

    replace c:\nul %1 >\nul
    if errorlevel 3 echo DIRECTORY %1 NOT FOUND

Or for something more robust, try DIR'ing the directory (or file):-

    dir /ad %1 | find "file(s)" >>tmp1.bat
    call tmp1
    if "%error%"=="" echo DIRECTORY %1 NOT FOUND

Where tmp1.bat initially contains just SET ERROR= with no trailing <CR>.
--
John Savage               koala@sydney.dialix.com.au
Technical Details
Message-ID: <4b8n7q$1t0$1@sydney.DIALix.oz.au>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <DIowsq.EsK@seas.ucla.edu> <817947303snz@martian.demon.co.uk> <DJ2ywJ.FJ8@seas.ucla.edu>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d683,4daf6881b9f4af91,start
X-Google-Attributes: gid10d683,public
X-Google-Thread: 104805,4daf6881b9f4af91,start
X-Google-Attributes: gid104805,public
X-Google-Thread: f71eb,4daf6881b9f4af91,start
X-Google-Attributes: gidf71eb,public
From: John Savage <koala@sydney.dialix.com.au>
Subject: Re: How to know if a dir exists (Batch way)
Date: 1995/12/20
Message-ID: <4b8n7q$1t0$1@sydney.DIALix.oz.au>
X-Deja-AN: 122354413
sender: koala@sydney.DIALix.oz.au
references: <DIowsq.EsK@seas.ucla.edu> <817947303snz@martian.demon.co.uk> <DJ2ywJ.FJ8@seas.ucla.edu>
followup-to: comp.os.msdos.misc,alt.msdos.batch
organization: Gumleaf Smoke Signals Telegraph Co.
newsgroups: comp.os.msdos.misc,alt.msdos.batch,aus.computers.ibm-pc