Page 1 of 1 1
Topic Options
#192607 - 2009-02-26 10:13 PM "OR" statement for if a file Exists
jeff_eisenberg Offline
Fresh Scripter

Registered: 2009-02-26
Posts: 45
Loc: CA
I know this is a basic feature but I can't figure out how to make it work:

IF EXIST "C:\file1.txt" OR "C:\file2.txt"
DO SOMETHING
ENDIF

I want to do something if one or both files exist. It seems that when I use the OR statement, it runs the program no matter what. Even if neither of the files exist.

Is there a different way to do this or am I using the wrong syntax?

Thanks,

Top
#192608 - 2009-02-26 10:28 PM Re: "OR" statement for if a file Exists [Re: jeff_eisenberg]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Welcome!

Close, but your cigar isn't lit.. ;\)

 Code:
If Exist($File1) Or Exist($File2)
  Do Something...
EndIf


You need both Exist functions.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#192609 - 2009-02-26 10:29 PM Re: "OR" statement for if a file Exists [Re: jeff_eisenberg]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I would say, look in to manual.
exist does have it's brackets for a reason.
_________________________
!

download KiXnet

Top
#192610 - 2009-02-26 10:30 PM Re: "OR" statement for if a file Exists [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
damn, I should have been faster.
I was gonna slap with trout everyone giving silver platter here, but can't now...
_________________________
!

download KiXnet

Top
#192611 - 2009-02-26 10:32 PM Re: "OR" statement for if a file Exists [Re: Glenn Barnas]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Thinking about it.. in your method, you are saying
"If File1 exists Or 'This string' is not empty..."

Since "this string" is never empty, the overall IF is always true. It would not matter what you put in the string, as long as something was there.. that's why it always did something.

Also, since Exist is a function, it needs the () around the parameters.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#192612 - 2009-02-26 10:33 PM Re: "OR" statement for if a file Exists [Re: Lonkero]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Dude, you should know better - I never give more than tin-platter code, otherwise coders won't learn to become better coders.. ;\)

Glenn

PS - Keep the trout in the fish tank! \:D
_________________________
Actually I am a Rocket Scientist! \:D

Top
#192613 - 2009-02-26 10:39 PM Re: "OR" statement for if a file Exists [Re: Glenn Barnas]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Or something like this.


 Code:
Break On
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')
$SO=SetOption('WrapAtEOL','On')


Dim $List, $Entry
$List = ReadFile('C:\TEMP\LIST.TXT')
For Each $Entry in $List
  If $Entry
    If Exist($Entry)
      ; Do something....
    Else
      $Entry ?
      ;Show the file listing for the file not found in the list.
    EndIf
  EndIf
Next


Function ReadFile($file)
  Dim $lf, $f, $_, $t
  $lf=CHR(10)
  $f=FreeFileHandle
  $_=Open($f,$file)
    If @ERROR Exit @ERROR EndIf
    Do $t=$t+$lf+ReadLine($f) Until @ERROR
    $_=Close($f)
  $ReadFile=Split(SubStr($t,2),$lf)
EndFunction


Top
#192614 - 2009-02-26 10:41 PM Re: "OR" statement for if a file Exists [Re: NTDOC]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
slappady slap!
_________________________
!

download KiXnet

Top
#192616 - 2009-02-26 10:45 PM Re: "OR" statement for if a file Exists [Re: Glenn Barnas]
jeff_eisenberg Offline
Fresh Scripter

Registered: 2009-02-26
Posts: 45
Loc: CA
No I'm smoking.

Thanks guys

Top
#192617 - 2009-02-26 10:45 PM Re: "OR" statement for if a file Exists [Re: jeff_eisenberg]
jeff_eisenberg Offline
Fresh Scripter

Registered: 2009-02-26
Posts: 45
Loc: CA
I mean now I'm smoking
Top
#192618 - 2009-02-26 10:48 PM Re: "OR" statement for if a file Exists [Re: jeff_eisenberg]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
smoking is bad for you! ;\)
_________________________
!

download KiXnet

Top
#192619 - 2009-02-26 10:57 PM Re: "OR" statement for if a file Exists [Re: Lonkero]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
I didn't tell you to smoke! Just light the cigar.. you were that close! \:D

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1257 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.062 seconds in which 0.029 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org