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

#1
ZEUS__

ZEUS__

    Member

  • Member
  • PipPip
  • 194 posts
  • Joined 03-January 08
  • OS:Windows 7 x64
  • Country: Country Flag
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__, 12 May 2010 - 06:26 PM.

Champion

Posted Image



How to remove advertisement from MSFN

#2
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,421 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
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



GunSmokingMan



#3
ZEUS__

ZEUS__

    Member

  • Member
  • PipPip
  • 194 posts
  • Joined 03-January 08
  • OS:Windows 7 x64
  • Country: Country Flag
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__, 12 May 2010 - 06:25 PM.

Champion

Posted Image


#4
ZEUS__

ZEUS__

    Member

  • Member
  • PipPip
  • 194 posts
  • Joined 03-January 08
  • OS:Windows 7 x64
  • Country: Country Flag
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

Champion

Posted Image


#5
5eraph

5eraph

    Update Packrat

  • MSFN Sponsor
  • 1,165 posts
  • Joined 04-July 05
  • OS:XP Pro x64
  • Country: Country Flag

Donator

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


#6
ZEUS__

ZEUS__

    Member

  • Member
  • PipPip
  • 194 posts
  • Joined 03-January 08
  • OS:Windows 7 x64
  • Country: Country Flag
thanks @5eraph. it's much more clear:)
Champion

Posted Image


#7
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,557 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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!

#8
ZEUS__

ZEUS__

    Member

  • Member
  • PipPip
  • 194 posts
  • Joined 03-January 08
  • OS:Windows 7 x64
  • Country: Country Flag
thank you so much @Yzöwl :thumbup
Champion

Posted Image


#9
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,657 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
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

#10
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,557 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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!

#11
PROBLEMCHYLD

PROBLEMCHYLD

    The Resurrector for old Windows OS

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,531 posts
  • Joined 07-October 05
  • OS:98SE
  • Country: Country Flag
I need something similar.

IF NOT EXIST FILE1 OR FILE2 THEN DEL FILE3 ;)

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


#12
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,557 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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


#13
PROBLEMCHYLD

PROBLEMCHYLD

    The Resurrector for old Windows OS

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,531 posts
  • Joined 07-October 05
  • OS:98SE
  • Country: Country Flag


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, 10 April 2013 - 12:02 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


#14
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,421 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
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 



GunSmokingMan



#15
PROBLEMCHYLD

PROBLEMCHYLD

    The Resurrector for old Windows OS

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,531 posts
  • Joined 07-October 05
  • OS:98SE
  • Country: Country Flag

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

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


#16
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,421 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
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



GunSmokingMan



#17
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,557 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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?

#18
PROBLEMCHYLD

PROBLEMCHYLD

    The Resurrector for old Windows OS

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,531 posts
  • Joined 07-October 05
  • OS:98SE
  • Country: Country Flag

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.

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


#19
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,557 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

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



#20
PROBLEMCHYLD

PROBLEMCHYLD

    The Resurrector for old Windows OS

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,531 posts
  • Joined 07-October 05
  • OS:98SE
  • Country: Country Flag

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.

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


#21
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,801 posts
  • Joined 12-May 07
  • OS:none specified
  • Country: Country Flag
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, 10 April 2013 - 07:05 PM.

Posted Image


#22
PROBLEMCHYLD

PROBLEMCHYLD

    The Resurrector for old Windows OS

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,531 posts
  • Joined 07-October 05
  • OS:98SE
  • Country: Country Flag
FILE.THREE keeps getting deleted even if FILE.ONE or FILE.TWO exist.

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


#23
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,801 posts
  • Joined 12-May 07
  • OS:none specified
  • Country: Country Flag
Hmmm I don't see how. Could you please post the code you are using?

Cheers and Regards

Posted Image


#24
PROBLEMCHYLD

PROBLEMCHYLD

    The Resurrector for old Windows OS

  • Member
  • PipPipPipPipPipPipPipPip
  • 2,531 posts
  • Joined 07-October 05
  • OS:98SE
  • Country: Country Flag

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, 10 April 2013 - 07:56 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


#25
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,801 posts
  • Joined 12-May 07
  • OS:none specified
  • 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

Edited by bphlpt, 10 April 2013 - 08:17 PM.

Posted Image





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users