[futurebasic] Re: [FB] Watched folder

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : April 1999 : Group Archive : Group : All Groups

From: Rick Brown <rbrown@...>
Date: Thu, 08 Apr 1999 20:19:24 -0500

Paul Bruneau wrote:

> Hi all.
>
> I some time ago wrote a program which watches a folder, then if it finds
> a file in that folder it sends it down the serial port to a Zebra printer.
>
> All works well except for larger files. Sometimes the program will start
> to do its stuff to a file that isn't completely there yet (due to its
> larger size), and the transfer fails. Can someone tell me a good way to
> make my program hold off until the file is completely copied over there?
> I'm currently not getting (or maybe not checking) for any error messages
> from the system.

I would recommend periodically checking the "in use" flag that's returned by FN
GETCATINFO.  The flag will be "true" while the file is being copied to your folder,
and will change to "false" when the copy is complete.  Just call the following
function once you detect the file in your folder:

LOCAL FN WaitTillIdle
  'Waits until the file specified by gFilename$
  'and gIncomingVol% is no longer "in use"
  DIM pb.ioHFQElSiz, OSErr, inUse
  pb.ioNamePtr& = @gFilename$
  pb.ioVRefNum% = gIncomingVol%
  pb.FDirIndex% = 0
  DO
    HANDLEEVENTS 'give time to other processes
    pb.ioDirID&  'must reset this each time
    OSErr = FN GETCATINFO(@pb)
    inUse = ((PEEK(@pb.ioFlAttrib) AND BIT(7)) <> 0)
  UNTIL NOT inUse
END FN
'-----------------

- Rick