Page 1 of 1

Can Wait for file Activity use Wildcards?

Posted: Thu Nov 30, 2006 5:02 pm
by tracy
I want to wait for the appearance or disappearance of any file with a certain extension.

So I tried to put something like:
*.txt
in the filename box, but it doesn't work. It looks like it's looking for a filename that has an asterick-period-t-x-t as opposed to anything that ends with .txt.

Is there a different wildcard character? Or is this not possible?

Posted: Thu Nov 30, 2006 5:08 pm
by narasimha
Welcome Aboard!

It is not possible to use wildcard characters while using the Wait_For_File_Activity stage

Posted: Thu Nov 30, 2006 5:14 pm
by tracy
Thanks! Then I will stop trying to get it to do it.

Posted: Thu Nov 30, 2006 5:30 pm
by narasimha
Can you mark it as resolved :roll:

Posted: Thu Nov 30, 2006 5:58 pm
by chulett
Perhaps somone should actually post a resolution first? What would you suggest as an alternative? I'd hate to see Tracy's first foray into DSXchange end with what basically amounts to a one word answer - 'nope'. :wink:

Posted: Thu Nov 30, 2006 6:34 pm
by ray.wurlod
Well, not trying to do something that won't work is a resolution of a kind.

The usual solution to this is to create your own routine. Something like this one.

Code: Select all

FUNCTION WaitForFile(WildCard, TimeOut)
* Returns 0 if there is at least one file that matches WildCard,
* returns 1 if the timeout (given in seconds) expires.

* Ray Wurlod, 01 Dec 2006.

Equate RoutineName To "WaitForFile"
Equate DELAY To 5         ; * time to wait between checks
$DEFINE LOGGING

* Set up for operating system
If System(91) = 0
Then
   Shell = "UNIX"
   Command = "ls -1 " : WildCard
End
Else
   Shell = "DOS"
   Command = "dir " : WildCard
End

* We rely on the fact that "not found" will set exit status to a non-zero value.
* This is $? in UNIX and %ERRORLEVEL% in DOS, but is captured automatically for us by DSExecute.
Timer = 0
Loop
   Call DSExecute(Shell, Command, Output, ExitStatus)
While ExitStatus <> 0 And Timer < TimeOut
   Timer += DELAY
   Sleep DELAY
Repeat

Ans = Not(Not(ExitStatus))

$IFDEF LOGGING
If ExitStatus() <> 0
Then
   * Decompose wildcard into directory and entryname components
   Call !GET.PATHNAME(WildCard, DirPath, EntryName, StatusCode)
   Message = "No file matching " : Quote(EntryName) : " found in " : Quote(DirPath) : "."
   Call DSLogWarn(Message, RoutineName)
End
$ENDIF

RETURN(Ans)