Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 



ZEUS__

help to IF NOT EXIST batch command

Recommended Posts

ZEUS__    0

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__

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

Share this post


Link to post
Share on other sites
ZEUS__    0

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__

Share this post


Link to post
Share on other sites
ZEUS__    0

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

Share this post


Link to post
Share on other sites
Guest   
Guest

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

Share this post


Link to post
Share on other sites
Yzöwl    30

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!

Share this post


Link to post
Share on other sites
jaclaz    939

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

Share this post


Link to post
Share on other sites
Yzöwl    30

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!

Share this post


Link to post
Share on other sites
Yzöwl    30

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

Share this post


Link to post
Share on other sites
PROBLEMCHYLD    44

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

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

Share this post


Link to post
Share on other sites
PROBLEMCHYLD    44

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

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.

×