Page 1 of 1

file write detection

Posted: Sun Jul 24, 2011 3:00 am
by Tenaja
I don't know if this is a PB coding issue or not, so I put it o/t.

How do you detect files written to or read from by another exe? For instance, a program that creates temporary files...I'd like to view those temp files.

Thanks.

Re: file write detection

Posted: Sun Jul 24, 2011 5:34 am
by netmaestro
This is by no means a comprehensive solution to your goal. This posting is meant to serve only as a light nudge in the direction you need to go. Put the path of your choice in the code, run it and see the notification that arises when you create a new file in the path or change an existing file:

Code: Select all

Procedure WatchDisk(lcPathSpec.s)
  lihNotify = FindFirstChangeNotification_(lcPathSpec, #True, #FILE_NOTIFY_CHANGE_LAST_WRITE)
  If lihNotify <= #INVALID_HANDLE_VALUE
    MessageRequester("Notice:","FindFirstChangeNotification failed. Error code: " + LTrim(Str(GetLastError_())))
    ProcedureReturn
  Else
    MessageRequester("Notice:","FindFirstChangfeNotification instantiation succeeded. Handle is: " + LTrim(Str(lihNotify)))
  EndIf
  
  liWaitReturn = WaitForSingleObject_(lihNotify, #INFINITE)
  If liWaitReturn >= #WAIT_FAILED
    MessageRequester("Notice:","WaitForSingleObject failed. Error is: " + LTrim(Str(GetLastError_())))
    ProcedureReturn
  Else
    MessageRequester("Notice:","Directory change in " + lcPathSpec + " occurred")
  EndIf
  
  liWaitReturn = FindCloseChangeNotification_(lihNotify)
  ProcedureReturn liWaitReturn
EndProcedure

Debug WatchDisk("d:\")
Again, just a nudge, I hope it helps you find your solution.

Re: file write detection

Posted: Tue Aug 02, 2011 8:27 pm
by Tenaja
netmaestro--that was a very good nudge; it does report when a change is made, but not what the change is. I hadn't looked at this issue since my post, but jpfiste posted a complete solution today:
http://purebasic.fr/english/viewtopic.php?f=12&t=47060

(and I added a followup question there, too...)

Thanks!