Fredledingue Posted June 16, 2006 Share Posted June 16, 2006 Is it possible to disable the "file not found" error in Batch scripts?Thanks. Link to comment Share on other sites More sharing options...
gunsmokingman Posted June 17, 2006 Share Posted June 17, 2006 Try this, it uses the If exist or if not exist statement. Cmd Promt@Echo OffCLSMode 75,5Color F3if exist Test.txt goto 000if not exist Test.txt goto 001:000CLSEcho.Echo Found The Fileset /p = Press Any Key To Close:001CLSEcho.Echo Can Not Found The Fileset /p = Press Any Key To CloseVbs Script, without reporting the missing fileDim Fso Set Fso = CreateObject("Scripting.FileSystemObject") If Fso.FileExists("Test.txt") Then MsgBox "Found The File", 0 + 32, "Confirm" End IfVbs Script, with reporting the missing fileDim 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 More sharing options...
spazmire11 Posted June 17, 2006 Share Posted June 17, 2006 (edited) you can also do it in one line of code:if exist "C:\windows\system32\ntoskrnl.exe" del "C:\windows\system32\ntoskrnl.exe" Edited June 17, 2006 by spazmire11 Link to comment Share on other sites More sharing options...
Yzöwl Posted June 17, 2006 Share Posted June 17, 2006 ntoskrnl.exe is a critical process in the boot-up cycle of your computer, so why use it in a delete example. Link to comment Share on other sites More sharing options...
Fredledingue Posted June 19, 2006 Author Share Posted June 19, 2006 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 More sharing options...
aquarius Posted July 17, 2006 Share Posted July 17, 2006 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> nulYou can do this for the whole batch by starting it this way:yourprog.cmd 2>nulTo 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 offif not %1!==/go! %0 /go 2> nulshift REM Put the rest of your program here, errors will not be displayed on STDOUTREM Example - dir without error:dir a-dir-that-doesnt-exist-ksjdhf-werweHave a nice day! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now