j0ep
(Fresh Scripter)
2003-10-02 06:10 PM
compare files in two arrays

How do I compare two arrays with files ?

for example:

1 array contains files in a directory, the second files that should be there. How do I compare these ?


Sealeopard
(KiX Master)
2003-10-02 06:14 PM
Re: compare files in two arrays

Take a look at ASCAN() and loop through it with the smaller array.

Les
(KiX Master)
2003-10-02 06:33 PM
Re: compare files in two arrays

I presume you mean filenames and not the actual file contents.

Richard H.Administrator
(KiX Supporter)
2003-10-03 10:27 AM
Re: compare files in two arrays

Sealeopard has pointed you in the right direction, but as this is starters here is an example to get you started (not tested).

Assuming $asFilesInDir contains a list of all the files actually in the directory and $asFilesRequired contains a list of all the files that *should* be in the directory:
code:
For Each $sFile In $asFilesInDir
$iFound=Ascan($asFilesRequired)
If ($iFound+1)
$asFilesRequired[$iFound]=""
$sFile "Required file present: "+$sFile+@CRLF
EndIf
Next

For Each $sFile in $asFilesRequired
If $sFile "Required file missing: "+$sFile+@CRLF EndIf
Next

This scriptlet will print a list of required files which are present, followed by a list of required files which are missing.

The required file array is sacrificial - if you want to run it on more than one directory you will need to make a copy first.

If you want to keep their status for using later, keep the status in an array which you maintain in parallel to the required files array.


j0ep
(Fresh Scripter)
2003-10-08 06:57 PM
Re: compare files in two arrays

Thanx all, especially Jens !!!

This is wat works for me :
code:
$allowedfiles = "1.tst","2.tst","3.tst"
$dirlist = dirlist("c:\test\*.*",)

For Each $sFile In $dirlist
$rc=isinarray($allowedfiles,$sFile)
If $rc = 0
? $sfile
EndIf
Next