Sign in to follow this  
Followers 0
legend

check if more than one file exists

8 posts in this topic

is it possible to check if 2 files exists, and if 1 of them exists then do something, and if they both or just 1 of them exists, then do something?

Share this post


Link to post
Share on other sites



something like

$bFileOne = FileExists ("file")
$bFileTwo = FileExists ("file")
If $bFileOne And $bFileTwo Then
 ; some action
ElseIf $bFileOne And ( Not $bFileTwo ) Then
 ; some action
ElseIf ( Not $bFileOne ) And $bFileTwo Then 
 ; some action
Else
 ; None of the files exist
EndIf

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

thanks :) but is it possible to make it like: if any of those two files exists then do something

Edited by legend

Share this post


Link to post
Share on other sites

$bFileOne = FileExists ("file")
$bFileTwo = FileExists ("file")
If $bFileOne And $bFileTwo Then
; Both Files Exist
;Now Do Something
ElseIf $bFileOne And ( Not $bFileTwo ) Then
; File Two Doesnt Exist
; DO whatever you want
ElseIf ( Not $bFileOne ) And $bFileTwo Then
; File One Doesnt Exist
Else
; None of the files exist
EndIf

Your Question has already been answered

1 person likes this

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

thanks alot :)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Doing between 2 and 6 compares (3 compound If/Then statements) is not very efficient when only 2 compares are needed:

$sResult1 = FileExists("C:test1.txt")
$sResult2 = FileExists("C:test2.txt")

If $sResult1 Then
    If $sResult2 Then
     ; do what I do when both 1 and 2 exist
    Else
        ; do what I do when only 1 exists
    EndIf
Else
    If $sResult2 Then
     ; do what I do when only 2 exists
    Else
     ; do what i do when neither 1 or 2 exist
    EndIf
EndIf

; a sneakier option
$sResult = FileExists("C:test1.txt")
$sResult += FileExists("C:test2.txt") * 2

Switch $sResult
   Case 0
        ; do what i do when neither 1 or 2 exist
    Case 1
     ; do what I do when only 1 exists
    Case 2
     ; do what I do when only 2 exists
    Case 3
     ; do what I do when both 1 and 2 exist
EndSwitch

typo

Edited by Spiff59

Share this post


Link to post
Share on other sites

@Spiff59,

Nothing sneaky about making the tool work for you, good job!

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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
Sign in to follow this  
Followers 0