|
Hello gents...
Got a request to create a script that will run continuously and give an alert whenever a new file is detected in a certain directory.
I have written the below that seems to work...Except for when the newest file is deleted..It then thinks the next newest (before the one deleted) is a new file.
I cant seem to think of a way to get around it. Any suggestions? Or if anyone know of a better way to do it...please let me know.
$directory = "L:\ScannedDocs\" Dim $file, $filedate, $line, $newfile, $newfiledate, $checks While @Error = 0 $dirfile = "%temp%\dirlist.xxx" If Exist ("$dirfile") Del "$dirfile" Endif $dirhandle = FreeFileHandle () Shell '%comspec% /c dir $directory /b /o:d > $dirfile' If Open ($dirhandle, $dirfile) = 0 $line = ReadLine ($dirhandle) If Len ("$line") > 0 $file = $line Endif While @Error = 0 $line = ReadLine ($dirhandle) If Len ("$line") > 0 $file = $line Endif Loop $filedate = GetFileTime ("$directory$file") $null = Close ($dirhandle) Del "$dirfile" Else $null = messagebox ("There was an error getting dir of "+$directory,"Error !!",0) Exit 1 Endif If $newfile <> $file or $newfiledate <> $filedate If $file <> "" and $filedate <> "" $newfile = $file $newfiledate = GetFileTime ("$directory$newfile") If $checks > 0 $null = messagebox ("There is a new file in the '$directory' folder"+@CRLF+"$newfile -- $newfiledate","New File !!",0) Endif Endif Endif $checks = $checks+1 Sleep 15 Loop
[ 07. October 2003, 23:55: Message edited by: CitrixMan ]
|