Welcome to MSFN

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.


ZEUS__

help to IF NOT EXIST batch command

34 posts in this topic

Hi,

I created an sfx installer with Windows Live Essential Addon Maker 3.5.. It works good but after install I want to copy two files that If a user has installed winamp or aimp it should copy to plugins folder.. I use if not exist because my winamp also install with this file. so I just want it if not exist.

here is my batch file;

@Echo Off
cwnd /HIDE @

start /wait wlm2009_416.exe
xcopy "Windows Live Messenger.lnk" "%ALLUSERSPROFILE%\Desktop" /Y /E
IF NOT EXIST "%programfiles%\Winamp\Plugins\gen_MSN.dll" (
xcopy "gen_MSN.dll" "%programfiles%\Winamp\Plugins\gen_MSN.dll"
) ELSE (
goto exits
:exits
EXIT

could anyone help please. it doesn't copy :S I don't understand why.

Edited by ZEUS__
0

Share this post


Link to post
Share on other sites

Maybe try this


@Echo Off
cwnd /HIDE @

start /wait wlm2009_416.exe
xcopy "Windows Live Messenger.lnk" "%ALLUSERSPROFILE%\Desktop" /Y /E

Set File="%programfiles%\Winamp\Plugins\gen_MSN.dll"

If Not Exist %File% Goto Work1

If Exist %File% Goto TheEnd

:Work1
xcopy "gen_MSN.dll" %File%
goto TheEnd



:TheEnd

Exit

0

Share this post


Link to post
Share on other sites

sorry but it didn't work. it doesn't seem to work, just I see xcopy.exe on task manager.

added:

in fact I need to copy two files if they not in their path..

one is; if not exist "%programfiles%\AIMP2\Plugins\gen_msn7.dll"

other is; if not exist "%programfiles%\Winamp\Plugins\gen_MSN.dll"

Edited by ZEUS__
0

Share this post


Link to post
Share on other sites

YAY, at the end. this is my art :P I tried something and I don't know how it works but it works like a charm :D

here's:

@Echo Off
cwnd /HIDE @

start /wait wlm2009_416.exe
xcopy "Windows Live Messenger.lnk" "%ALLUSERSPROFILE%\Desktop" /Y /E
IF NOT EXIST "%programfiles%\Winamp\Plugins\gen_MSN.dll" (
xcopy "gen_MSN.dll" "%programfiles%\Winamp\Plugins" /Y
) ELSE (
goto Aimp
)
:Aimp
IF NOT EXIST "%programfiles%\AIMP2\Plugins" (
goto 1
:1
md "%programfiles%\AIMP2\Plugins"
) ELSE (
goto 2
)
IF NOT EXIST "%programfiles%\AIMP2\Plugins\gen_msn7.dll" (
goto 2
:2
xcopy "gen_msn7.dll" "%programfiles%\AIMP2\Plugins" /Y
) ELSE (
goto exit
)
:exit
EXIT

0

Share this post


Link to post
Share on other sites

Nice. :)

Here's the same code, without the unnecessary GOTOs.

@Echo Off
cwnd /HIDE @

start /wait wlm2009_416.exe
xcopy "Windows Live Messenger.lnk" "%ALLUSERSPROFILE%\Desktop" /Y /E

IF NOT EXIST "%programfiles%\Winamp\Plugins\gen_MSN.dll" (
xcopy "gen_MSN.dll" "%programfiles%\Winamp\Plugins" /Y
)

IF NOT EXIST "%programfiles%\AIMP2\Plugins" (
md "%programfiles%\AIMP2\Plugins"
)

IF NOT EXIST "%programfiles%\AIMP2\Plugins\gen_msn7.dll" (
xcopy "gen_msn7.dll" "%programfiles%\AIMP2\Plugins" /Y
)
EXIT

0

Share this post


Link to post
Share on other sites

thanks @5eraph. it's much more clear:)

0

Share this post


Link to post
Share on other sites

Or perhaps this would make more sense…

@CWND /HIDE @

START /WAIT wlm2009_416.exe
COPY "Windows Live Messenger.lnk" "%AllUsersProfile%\Desktop"

IF NOT EXIST "%ProgramFiles%\Winamp\Plugins\gen_MSN.dll" (
COPY "gen_MSN.dll" "%ProgramFiles%\Winamp\Plugins")

IF NOT EXIST "%ProgramFiles%\AIMP2\Plugins\gen_msn7.dll" (
IF NOT EXIST "%ProgramFiles%\AIMP2\Plugins" (
MD "%ProgramFiles%\AIMP2\Plugins")
COPY "gen_msn7.dll" "%ProgramFiles%\AIMP2\Plugins")

The @Echo off wasn't required because the window was being hidden!

XCOPY isn't required since none of its special switches are required!

There's no need to check for the existence of the AIMP\Plugins directory unless the file doesn't exist, (that location would exist if the file was found in it)!

There's likely no need for the EXIT command, the script should end on its own!

0

Share this post


Link to post
Share on other sites

As a side note, and only as a "philosophical" point, with no practical use whatever :ph34r:, the only "bad" thing that can happen if you try mkdir giving an existing directory is that an error message will be output to STDERR, I have no idea (but it may be worth a test :unsure:) if by unconditionally making the dir anyway would it be faster than looping to the "directory" IF NOT EXIST, when a great number of file needs to be copied.

I.E. something like:

FOR %%? IN (
"%ProgramFiles%\Winamp\Plugins\gen_MSN.dll"
"%ProgramFiles%\AIMP2\Plugins\gen_msn7.dll"
) DO CALL :Copyfiles %%?
GOTO :EOF

:Copyfiles
MD "%~dp1" >NUL 2>&1
IF NOT EXIST "%~dpnx1" COPY "%~nx1" "%~dpnx1"
GOTO :EOF

jaclaz

0

Share this post


Link to post
Share on other sites

Also, you'll note that you've made no provision for the fact that it would be good practice to verify whether Winamp or AIMP are installed first. (or at the very least check that the AIMP and Winamp directories exist in %ProgramFiles%.) If they aren't there then it would be pointless creating folder structures and placing files there!

0

Share this post


Link to post
Share on other sites

I need something similar.

IF NOT EXIST FILE1 OR FILE2 THEN DEL FILE3 ;)

0

Share this post


Link to post
Share on other sites

I need something similar.

IF NOT EXIST FILE1 OR FILE2 THEN DEL FILE3 ;)

A couple of ideas

IF EXIST FILE.ONE (IF EXIST FILE.TWO (GOTO :NEXT))
DEL FILE.THREE
:NEXT

IF NOT EXIST FILE.ONE SET _OR=T
IF NOT EXIST FILE.TWO SET _OR=T
IF DEFINED _OR DEL FILE.THREE

0

Share this post


Link to post
Share on other sites

I need something similar.

IF NOT EXIST FILE1 OR FILE2 THEN DEL FILE3 ;)

A couple of ideas

IF EXIST FILE.ONE (IF EXIST FILE.TWO (GOTO :NEXT))
DEL FILE.THREE
:NEXT

IF NOT EXIST FILE.ONE SET _OR=T
IF NOT EXIST FILE.TWO SET _OR=T
IF DEFINED _OR DEL FILE.THREE

Thanks, but I'm trying to delete FILE.THREE only if FILE.ONE or FILE.TWO don't exist. Edited by PROBLEMCHYLD
0

Share this post


Link to post
Share on other sites

The VBS way of doing what you want.


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

If Not Fso.FileExists("Text1.txt") And _
Not Fso.FileExists("Text2.txt") Then
MsgBox "Delete Text3.txt"
Else
MsgBox "Text1 or Text2 Exists"
End If

0

Share this post


Link to post
Share on other sites

The VBS way of doing what you want.


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

If Not Fso.FileExists("Text1.txt") And _
Not Fso.FileExists("Text2.txt") Then
MsgBox "Delete Text3.txt"
Else
MsgBox "Text1 or Text2 Exists"
End If

Thanks, but I need it in BATCH format, because WSH is not present at the time. Also your script looks good but it didn't delete the file. I will have a use for it in the future. :thumbup
0

Share this post


Link to post
Share on other sites

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 If

Example VBS Delete to be added to above code


Fso.DeleteFile("FILE_PATH\FILE_NAME"),True

0

Share this post


Link to post
Share on other sites

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?

0

Share this post


Link to post
Share on other sites

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.
0

Share this post


Link to post
Share on other sites

I'm still not sure what you want!

Correct this:

FILE.ONE exists + FILE.TWO exists = Keep FILE.THREE

FILE.ONE exists + FILE.TWO absent = Delete FILE.THREE

FILE.ONE absent + FILE.TWO exists = Delete FILE.THREE

FILE.ONE absent + FILE.TWO absent = Keep FILE.THREE

0

Share this post


Link to post
Share on other sites

I'm still not sure what you want!

Correct this:

FILE.ONE exists + FILE.TWO exists = Keep FILE.THREE

FILE.ONE exists + FILE.TWO absent = Delete FILE.THREE

FILE.ONE absent + FILE.TWO exists = Delete FILE.THREE

FILE.ONE absent + FILE.TWO absent = Keep FILE.THREE

IF NOT EXIST FILE.ONE OR FILE.TWO DEL FILE.THREE

IF EXIST FILE.ONE OR FILE.TWO DON'T DELETE FILE.THREE

Remeber the (OR) because either file can be present. It doesn't need both files, just one or the other.

0

Share this post


Link to post
Share on other sites

So like this?


IF EXIST FILE.ONE (GOTO :NEXT)
IF EXIST FILE.TWO (GOTO :NEXT)
DEL FILE.THREE
:NEXT

or


IF NOT EXIST FILE.ONE (IF NOT EXIST FILE.TWO (DEL FILE.THREE))

Cheers and Regards

Edited by bphlpt
0

Share this post


Link to post
Share on other sites

FILE.THREE keeps getting deleted even if FILE.ONE or FILE.TWO exist.

0

Share this post


Link to post
Share on other sites

Hmmm I don't see how. Could you please post the code you are using?

Cheers and Regards

0

Share this post


Link to post
Share on other sites

Hmmm I don't see how. Could you please post the code you are using?

Cheers and Regards

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

This way is wrong because it deletes IRFTP.EXE before it checks for the next file.

Edited by PROBLEMCHYLD
0

Share this post


Link to post
Share on other sites

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

Edited by bphlpt
0

Share this post


Link to post
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.