Here's some code not specific to your problem but gives a general example of the usage of the dir() function
? "Scanning for tagfiles in: $tagfile_directory\" ; slash appended due to root dir bug
$Tagfile = ""

$FileName = Dir("$tagfile_directory\*.tag")
While ($FileName <> "") and (@ERROR = 0)
If $Tagfile = ""
$Tagfile = $Filename
? "Found: $tagfile_directory\$tagfile"
Else
? "Found: $tagfile_directory\$filename"
? "Error: Multiple tagfiles detected, script aborting"
; shell net send mis error message...
$Continue=1
Return
Endif
$Filename = Dir() ; retrieve next file
Loop
If $Tagfile = ""
? "No tagfiles found"
$Continue=1
Return
Endif

------------------
K Torkelson
Sys Admin Analyst
ktorkelson@providentfunding.com