Computing.Net > Forums > Disk Operating System > Directory already exists

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Directory already exists

Reply to Message Icon

Name: Miskva
Date: January 20, 2001 at 14:03:52 Pacific
Comment:

I'm using a batch program to manage some directories, but when creating dirs, when they exist he answers "Directory already exists", pretty normal. But I don't want that output on screen ... No, redirecting doesnt help, I need something like the unix method "2>" to redirect basic error messages. A shortcut should be to know if dir exists, but the "if" command doesnt seem to work with dirs on DOS/W95 ... Anybody ???



Sponsored Link
Ads by Google

Response Number 1
Name: Michael
Date: January 20, 2001 at 17:51:08 Pacific
Reply:

Miskva,

The syntax for checking for a directory existance is...
if exist c:\windows\nul then goto exists

The most important thing to note is that you have to check for the 'nul file' in the particular directory whose existance you're checking for. If the above example, I checked for the existance of the windows directory on drive C:

Hope that helped,
-Michael


0

Response Number 2
Name: Miskva
Date: January 21, 2001 at 07:37:23 Pacific
Reply:

Michael, it certainly helped. I have been looking for this answer for at least one year now ... that is, without the help of internet ... This forum is excellent !


0

Response Number 3
Name: Laurence
Date: January 21, 2001 at 11:39:19 Pacific
Reply:

I have another answer
command nul /cmd whatever

In a batch file, you would use:
%comspec% nul /cmd whatever


Batfiles: The DOS batch file programming handbook



0

Response Number 4
Name: Michael
Date: January 21, 2001 at 13:06:28 Pacific
Reply:

As usual Laurence, you lost me. LOL, care to explain what you mean / how that works?

-Michael


0

Response Number 5
Name: Laurence
Date: January 27, 2001 at 23:21:06 Pacific
Reply:

Command is command.com, the command interpreter. DOS automatically sets the %comspec% variable to reference command.com on boot. In a batch file it is normally adviseable to use %comspec% instead of command (or command.com) because it is slightly faster (DOS doesn't have to look for it), and more importantly, 'command' may not necessarily be in the DOS path.

command nul /cmd whatever

In a batch file, you would use:
%comspec% nul /cmd whatever

The nul after command.com tells DOS to redirect the output of command.com to the nul device which means it will not appear on screen. This technique also works with error messages, so if the directory in the above examples already exists, no error message will appear. Naturally, if the directory can be created, it will be. The only drawback is if there exists a file with the same name as the directory you wish to create. To cover this possibility, just add an extra test.

@ECHO off
IF exist whatever ECHO unable to create directory due to existing file with same name
%comspec% nul /cmd whatever
I hope this is clearer :-).


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon

don't know how tu use kil... bat file should delete it...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Directory already exists

Sudirectory or file already exists www.computing.net/answers/dos/sudirectory-or-file-already-exists/15462.html

Formatting an already existing HD .... www.computing.net/answers/dos/formatting-an-already-existing-hd-/9484.html

DOS copy command without "Overwrite?" message www.computing.net/answers/dos/dos-copy-command-without-overwrite-message/4243.html