Page 1 of 1 1
Topic Options
#46264 - 2003-10-02 06:10 PM compare files in two arrays
j0ep Offline
Fresh Scripter

Registered: 2003-09-26
Posts: 14
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 ?

Top
#46265 - 2003-10-02 06:14 PM Re: compare files in two arrays
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Take a look at ASCAN() and loop through it with the smaller array.
_________________________
There are two types of vessels, submarines and targets.

Top
#46266 - 2003-10-02 06:33 PM Re: compare files in two arrays
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I presume you mean filenames and not the actual file contents.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#46267 - 2003-10-03 10:27 AM Re: compare files in two arrays
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
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.

Top
#46268 - 2003-10-08 06:57 PM Re: compare files in two arrays
j0ep Offline
Fresh Scripter

Registered: 2003-09-26
Posts: 14
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


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 557 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.056 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

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