Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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 ???

Miskva,
The syntax for checking for a directory existance is...
if exist c:\windows\nul then goto existsThe 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

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 !

I have another answer
command nul /cmd whateverIn a batch file, you would use:
%comspec% nul /cmd whatever

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 whateverThe 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 :-).

![]() |
don't know how tu use kil...
|
bat file should delete it...
|

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