Jump to content

Turning off "file not found" error


Recommended Posts


Try this, it uses the If exist or if not exist statement.

Cmd Promt

@Echo Off
CLS
Mode 75,5
Color F3

if exist Test.txt goto 000

if not exist Test.txt goto 001

:000
CLS
Echo.
Echo Found The File
set /p = Press Any Key To Close

:001
CLS
Echo.
Echo Can Not Found The File
set /p = Press Any Key To Close

Vbs Script, without reporting the missing file

Dim Fso 
Set Fso = CreateObject("Scripting.FileSystemObject")

If Fso.FileExists("Test.txt") Then
MsgBox "Found The File", 0 + 32, "Confirm"
End If

Vbs Script, with reporting the missing file

Dim Fso 
Set Fso = CreateObject("Scripting.FileSystemObject")

If Fso.FileExists("Test.txt") Then
MsgBox "Found The File", 0 + 32, "Confirm"
Else
MsgBox "Missing The File", 0 + 32, "Missing"
End If

Link to comment
Share on other sites

Thanks for your replies, but I wanted to know if there is a way to turn it off by default like turining echo off....

"If file exists then..." doesn't apply in this case because I'm annoyed by the "file not found" error with the DIR command.

Link to comment
Share on other sites

  • 4 weeks later...

Hello!

You can redirect STDERR to nul allmost like in Unix.

Redirect a commands stderr (channel 2) to nul (yes there are a couple more channels :-)

dir sdlkfn  2> nul

You can do this for the whole batch by starting it this way:

yourprog.cmd 2>nul

To conclude, your program can restart itself, with stderr redirected to nul, in this manner,

so that you don't have to start it like above:

@echo off
if not %1!==/go! %0 /go 2> nul
shift

REM Put the rest of your program here, errors will not be displayed on STDOUT

REM Example - dir without error:
dir a-dir-that-doesnt-exist-ksjdhf-werwe

Have a nice day! :hello:

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...