Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account


Photo

help to IF NOT EXIST batch command

- - - - -

  • Please log in to reply
33 replies to this topic

#26
PROBLEMCHYLD

PROBLEMCHYLD

    The Resurrector for old Windows OS

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,528 posts
  • OS:98SE
  • Country: Country Flag

So do either of these work?

@ECHO OFF
IF EXIST %WINDIR%\SYSTEM\NSCIRDA.SYS (GOTO :NEXT)
IF EXIST %WINDIR%\SYSTEM\SMCIRDA.SYS (GOTO :NEXT)
DEL %WINDIR%\SYSTEM\IRFTP.EXE
:NEXT
CLS

@ECHO OFF
IF NOT EXIST %WINDIR%\SYSTEM\NSCIRDA.SYS (IF NOT EXIST %WINDIR%\SYSTEM\SMCIRDA.SYS DEL %WINDIR%\SYSTEM\IRFTP.EXE)
CLS

Cheers and Regards

No, they don't work. they keep deleting FILE.THREE/IRFTP.EXE
I'm on using Win98 BTW.

Edited by PROBLEMCHYLD, 10 April 2013 - 08:39 PM.

Believe God is the Alpha and Omega.
Believe Jesus Christ died for our sins.
Repent for your sins now or there will be
BLOOD

The Path to God


U98SESP3 03-11-2013



How to remove advertisement from MSFN

#27
5eraph

5eraph

    Update Packrat

  • MSFN Sponsor
  • 1,144 posts
  • OS:XP Pro x64
  • Country: Country Flag

Donator

What is the value of %WinDir%? Does it have spaces?

#28
PROBLEMCHYLD

PROBLEMCHYLD

    The Resurrector for old Windows OS

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,528 posts
  • OS:98SE
  • Country: Country Flag

So do either of these work?

@ECHO OFF
IF EXIST %WINDIR%\SYSTEM\NSCIRDA.SYS (GOTO :NEXT)
IF EXIST %WINDIR%\SYSTEM\SMCIRDA.SYS (GOTO :NEXT)
DEL %WINDIR%\SYSTEM\IRFTP.EXE
:NEXT
CLS

Yes, this works but not with the original Win98 command.com. It works when I run it in cmd.exe, which is win95cmd.exe renamed. Thanks and sorry for wasting your time.

Believe God is the Alpha and Omega.
Believe Jesus Christ died for our sins.
Repent for your sins now or there will be
BLOOD

The Path to God


U98SESP3 03-11-2013


#29
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,796 posts
  • OS:none specified
  • Country: Country Flag
If spaces are involved anywhere in the path, then these should work with cmd.exe:

@ECHO OFF
IF EXIST "%WINDIR%\SYSTEM\NSCIRDA.SYS" (GOTO :NEXT)
IF EXIST "%WINDIR%\SYSTEM\SMCIRDA.SYS" (GOTO :NEXT)
DEL "%WINDIR%\SYSTEM\IRFTP.EXE"
:NEXT
CLS

@ECHO OFF
IF NOT EXIST "%WINDIR%\SYSTEM\NSCIRDA.SYS" (IF NOT EXIST "%WINDIR%\SYSTEM\SMCIRDA.SYS" DEL "%WINDIR%\SYSTEM\IRFTP.EXE")
CLS

If you really needed to use command.com, then the commands above should still work if you used the 8.3 version of the paths (without the quotes).

As to command.com vs cmd.exe, a couple of the main differences in support of using cmd.exe in most cases are:

command.com is 16-bit while cmd.exe is 32-bit
command.com can not handle long file names, spaces in the names, or quotes around the names
cmd.exe is available in 64-bit versions of XP+

Cheers and Regards

Posted Image


#30
CharlotteTheHarlot

CharlotteTheHarlot

    MSFN Master

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,054 posts
  • OS:none specified
  • Country: Country Flag
First, as previously mentioned, always use the quotes!

Second, using global variables are nice and all, but sometimes are overkill. They make sense when designing a batch file to be ported among several systems, something that most people don't do.

The problem is that variables are easily changed by people, other batch files or by malware. Infamously it was often done by using '=' ( assignment ) rather than '==' ( test if equal ). The re-assignment would then cause all manner of havoc. I usually suggest hardcoding paths to save headaches, especially for core files in C:\Windows\System ( Win9x ) or C:\Windows\System32 ( WinXP+ ). Earlier NT and 2K might have been in \WinNT but unless running on an older one is a real possibility, avoid it. Additionally, IMHO I would always avoid RD or Del or similar destructive commands using easily changed variables.

In your batch file do a sanity check ...

echo.
echo WinDir is set to %WinDir%
echo.


This will tell you what path is being fed to you and if it contains a trailing backslash already.

An overall safer way might be using a local variable in the batch file perhaps called Target. To delete it ...

set Target="C:\Example File Path\Filename.exe"
if not exist %Target% echo File does not exist: %Target%
if exist %Target% del %Target%


Also, someone above used this example...

IF EXIST "%WINDIR%\SYSTEM\NSCIRDA.SYS" (GOTO :NEXT)

... which should be ...

IF EXIST "%WINDIR%\SYSTEM\NSCIRDA.SYS" GOTO NEXT

... because the colon does not belong there. Or better ...

set Target="C:\Windows\System\Nscirda.sys"
if exist %Target% goto NEXT

... Let him who hath understanding reckon the Number Of The Beast ...


#31
PROBLEMCHYLD

PROBLEMCHYLD

    The Resurrector for old Windows OS

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,528 posts
  • OS:98SE
  • Country: Country Flag
It seems all of the methods work under certain conditions. Windows 98 native COMMAND.COM didn't understand (GOTO :NEXT)
but understood GOTO NEXT. WIN95CMD.EXE file understands both. So it seems certain flags/pipes/variables etc..,.. are recognized by both, but the WIN95CMD.EXE seems to recognize most if not all. Thanks guys, its working smoothly.

Believe God is the Alpha and Omega.
Believe Jesus Christ died for our sins.
Repent for your sins now or there will be
BLOOD

The Path to God


U98SESP3 03-11-2013


#32
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,530 posts
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

Why could you not simply correct the first word after the equals symbol in each of the four cases I provided!

I think that it may be you who is misunderstanding OR!

You now seem to only want FILE.THREE to be deleted if both of the other two files do not exist.

IF NOT EXIST "FILE.ONE" (SET _=BO)
IF NOT EXIST "FILE.TWO" (SET _=%_%TH)
IF %_%==BOTH DEL "FILE.THREE"
So in summary:
  • IF BOTH FILE.ONE AND FILE.TWO DO NOT EXIST
    use the above example
  • IF AT LEAST ONE OF FILE.ONE OR FILE.TWO DO NOT EXIST
    use either of the two examples I provided in my original post


#33
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,418 posts
  • OS:none specified
  • Country: Country Flag
Yzöwl did you look at post 14 it was the VBS way of doing what PROBLEMCHYLD wanted done.
If you read it and it really simple if the 2 files are not there then delete file 3, I am Dyslexic and could
understand what PROBLEMCHYLD wanted.

Yzöwl cool code :thumbup


GunSmokingMan



#34
tomasz86

tomasz86

    www.windows2000.tk

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,510 posts
  • OS:XP Pro x86
  • Country: Country Flag

What is the value of %WinDir%? Does it have spaces?

The Windows folder can't have spaces so you don't need quotes (unless you set the variables manually to something else but it's not the case here). Microsoft themselves usually don't use quotes when pointing to %windir% / %systemroot% in their patches.


I usually suggest hardcoding paths to save headaches, especially for core files in C:\Windows\System ( Win9x ) or C:\Windows\System32 ( WinXP+ ). Earlier NT and 2K might have been in \WinNT but unless running on an older one is a real possibility, avoid it.

Newer Windows can also use WINNT, ex. when you upgraded your system from Windows 2000 to XP, later upgraded XP to Vista, and Vista to 7, etc.

Edited by tomasz86, 11 April 2013 - 02:12 PM.

post-47483-1123010975.png
Unofficial Service Pack 5.2 for MS Windows 2000 <- use this topic if you need help with UURollup, Update Rollup 2 and other unofficial packages




1 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users


    Bing (1)


How to remove advertisement from MSFN