gunsmokingman Posted April 10, 2013 Posted April 10, 2013 It does not delete, I just posted to show how it would be done in VBS and left the delete out.Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject") If Not Fso.FileExists("Text1.txt") And _ Not Fso.FileExists("Text2.txt") Then'-> Code Here To Delete Or Do Something MsgBox "Delete Text3.txt" Else MsgBox "Text1 or Text2 Exists" End IfExample VBS Delete to be added to above codeFso.DeleteFile("FILE_PATH\FILE_NAME"),True
Yzöwl Posted April 10, 2013 Posted April 10, 2013 PROBLEMCHYLD, are you suggesting that you do not wish to delete FILE.THREE if neither file exits, only if just one of them doesn't?
PROBLEMCHYLD Posted April 10, 2013 Posted April 10, 2013 PROBLEMCHYLD, are you suggesting that you do not wish to delete FILE.THREE if neither file exits, only if just one of them doesn't?Yes one or the other. If neither file exist then delete file3. If one or the other file exist, leave file3 alone. Im half sleep. Sorry bout that.
Yzöwl Posted April 10, 2013 Posted April 10, 2013 I'm still not sure what you want!Correct this:FILE.ONE exists + FILE.TWO exists = Keep FILE.THREEFILE.ONE exists + FILE.TWO absent = Delete FILE.THREEFILE.ONE absent + FILE.TWO exists = Delete FILE.THREEFILE.ONE absent + FILE.TWO absent = Keep FILE.THREE
PROBLEMCHYLD Posted April 10, 2013 Posted April 10, 2013 I'm still not sure what you want!Correct this:FILE.ONE exists + FILE.TWO exists = Keep FILE.THREEFILE.ONE exists + FILE.TWO absent = Delete FILE.THREEFILE.ONE absent + FILE.TWO exists = Delete FILE.THREEFILE.ONE absent + FILE.TWO absent = Keep FILE.THREEIF NOT EXIST FILE.ONE OR FILE.TWO DEL FILE.THREEIF EXIST FILE.ONE OR FILE.TWO DON'T DELETE FILE.THREERemeber the (OR) because either file can be present. It doesn't need both files, just one or the other.
bphlpt Posted April 11, 2013 Posted April 11, 2013 (edited) So like this?IF EXIST FILE.ONE (GOTO :NEXT)IF EXIST FILE.TWO (GOTO :NEXT)DEL FILE.THREE:NEXTorIF NOT EXIST FILE.ONE (IF NOT EXIST FILE.TWO (DEL FILE.THREE))Cheers and Regards Edited April 11, 2013 by bphlpt
PROBLEMCHYLD Posted April 11, 2013 Posted April 11, 2013 FILE.THREE keeps getting deleted even if FILE.ONE or FILE.TWO exist.
bphlpt Posted April 11, 2013 Posted April 11, 2013 Hmmm I don't see how. Could you please post the code you are using?Cheers and Regards
PROBLEMCHYLD Posted April 11, 2013 Posted April 11, 2013 (edited) Hmmm I don't see how. Could you please post the code you are using?Cheers and Regards@ECHO OFFIF NOT EXIST %WINDIR%\SYSTEM\NSCIRDA.SYS DEL %WINDIR%\SYSTEM\IRFTP.EXEIF NOT EXIST %WINDIR%\SYSTEM\SMCIRDA.SYS DEL %WINDIR%\SYSTEM\IRFTP.EXECLSThis way is wrong because it deletes IRFTP.EXE before it checks for the next file. Edited April 11, 2013 by PROBLEMCHYLD
bphlpt Posted April 11, 2013 Posted April 11, 2013 (edited) So do either of these work?@ECHO OFFIF EXIST %WINDIR%\SYSTEM\NSCIRDA.SYS (GOTO :NEXT)IF EXIST %WINDIR%\SYSTEM\SMCIRDA.SYS (GOTO :NEXT)DEL %WINDIR%\SYSTEM\IRFTP.EXE:NEXTCLS@ECHO OFFIF NOT EXIST %WINDIR%\SYSTEM\NSCIRDA.SYS (IF NOT EXIST %WINDIR%\SYSTEM\SMCIRDA.SYS DEL %WINDIR%\SYSTEM\IRFTP.EXE)CLSCheers and Regards Edited April 11, 2013 by bphlpt
PROBLEMCHYLD Posted April 11, 2013 Posted April 11, 2013 (edited) So do either of these work?@ECHO OFFIF EXIST %WINDIR%\SYSTEM\NSCIRDA.SYS (GOTO :NEXT)IF EXIST %WINDIR%\SYSTEM\SMCIRDA.SYS (GOTO :NEXT)DEL %WINDIR%\SYSTEM\IRFTP.EXE:NEXTCLS@ECHO OFFIF NOT EXIST %WINDIR%\SYSTEM\NSCIRDA.SYS (IF NOT EXIST %WINDIR%\SYSTEM\SMCIRDA.SYS DEL %WINDIR%\SYSTEM\IRFTP.EXE)CLSCheers and RegardsNo, they don't work. they keep deleting FILE.THREE/IRFTP.EXEI'm on using Win98 BTW. Edited April 11, 2013 by PROBLEMCHYLD
Guest Posted April 11, 2013 Posted April 11, 2013 What is the value of %WinDir%? Does it have spaces?
PROBLEMCHYLD Posted April 11, 2013 Posted April 11, 2013 So do either of these work?@ECHO OFFIF EXIST %WINDIR%\SYSTEM\NSCIRDA.SYS (GOTO :NEXT)IF EXIST %WINDIR%\SYSTEM\SMCIRDA.SYS (GOTO :NEXT)DEL %WINDIR%\SYSTEM\IRFTP.EXE:NEXTCLSYes, 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.
bphlpt Posted April 11, 2013 Posted April 11, 2013 If spaces are involved anywhere in the path, then these should work with cmd.exe:@ECHO OFFIF EXIST "%WINDIR%\SYSTEM\NSCIRDA.SYS" (GOTO :NEXT)IF EXIST "%WINDIR%\SYSTEM\SMCIRDA.SYS" (GOTO :NEXT)DEL "%WINDIR%\SYSTEM\IRFTP.EXE":NEXTCLS@ECHO OFFIF NOT EXIST "%WINDIR%\SYSTEM\NSCIRDA.SYS" (IF NOT EXIST "%WINDIR%\SYSTEM\SMCIRDA.SYS" DEL "%WINDIR%\SYSTEM\IRFTP.EXE")CLSIf 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-bitcommand.com can not handle long file names, spaces in the names, or quotes around the namescmd.exe is available in 64-bit versions of XP+Cheers and Regards
CharlotteTheHarlot Posted April 11, 2013 Posted April 11, 2013 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
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now