News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

FileExist question

Started by brixton, June 05, 2006, 03:37:52 PM

Previous topic - Next topic

brixton

If you love somebody, set them free.
If they return, they were always yours. If they don't, they never were..

brixton

I'm surprised no-one noticed this mistake here!

Quote from: brixton on June 07, 2006, 11:10:53 PM..
@@:

      push 10
    call Sleep
      push OFFSET findfirstfilestruct
      push OFFSET existrule
    call FindFirstFile
      cmp eax, -1
  je @F
      push eax
    call FindClose
  jmp @B

@@:
...
This would result in an error if I kept calling this proc because I don't close the search handle.  Just had this exact problem and couldn't see why my program was looping forever when it shouldn't  :dance:
If you love somebody, set them free.
If they return, they were always yours. If they don't, they never were..

asmfan

Brixton, the true clean-style programming is unreachable;) good example for another thread just started a few time ago about all kind of nasty "leaks"... By the way you are not "no-one";)
Regards,
asmfan
Russia is a weird place

farrier

brixton,

You could also use:

ReadDirectoryChangesW

which can run in a thread and monitor a directory for file creation, modification, deletion, move from, and move to.  You could respond to a notification from this API and check for the file which has changed, or simply do your FindFirstFile.  The main advantage is you would not have to loop constantly--or with a delay--to monitor for a change.

Attached is a FASM program which demonstrates ReadDirectoryChangesW.  Put the program in the directory you want to monitor and it will put an entry in a ListView for all changed files.  The only thing that was found not to work was if a file was simply opened and closed.  The first access triggers a notification, but another notification is not triggered for 1 hour.

hth,

farrier


[attachment deleted by admin]
It is a GOOD day to code!
Some assembly required!
ASM me!
With every mistake, we must surely be learning. (George...Bush)

brixton

Thankyou both for your replies, very informative indeed!  I will have to look into that ReadDirectoryChangesW, looks very interesting.

And asmfan, I consider myself 'no-one' on this forum :(
If you love somebody, set them free.
If they return, they were always yours. If they don't, they never were..

no-one

Brixton,
You cannot be no-one because I am no-one.

no-one

brixton

So you are  :lol

Uh oh, first sign of madness;  I'm talking to no-one!

-brixton
If you love somebody, set them free.
If they return, they were always yours. If they don't, they never were..

no-one

Don't worry, no-one cares. :bdg

brixton

Did someone speak?  Oh, no-one did  :U
If you love somebody, set them free.
If they return, they were always yours. If they don't, they never were..