Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Mon Nov 18, 2019 12:58 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Folder Watcher
PostPosted: Thu Apr 07, 2011 10:31 am 
Offline

Joined: Thu Jan 24, 2008 2:43 pm
Posts: 40
Location: Sweden
Hi!

I found this pice of C++ code/tutorial:
http://www.relisoft.com/win32/watcher.html

Is it possible to implement the same API calls in a RB program? Is there any tutorial on how to do that, that could get me started?

Best regards
Ola


Top
 Profile  
Reply with quote  
 Post subject: Re: Folder Watcher
PostPosted: Thu Apr 07, 2011 11:28 am 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
Don't think you need any API calls..

Create a thread the monitors the COUNT parameter of the chosen folder... if that value changes from one call to the next, fire a custom event

Should be about 20 lines of RB code..... and no, I don't have a specific example.

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Folder Watcher
PostPosted: Thu Apr 07, 2011 12:22 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Yes, you can implement that API in RB. It falls in the advanced category of RB programming, though. You might find something in the Windows Functionality Suite on ARBP to help you, but I don't know for sure. Dave's method, while not perfect, may be good enough for your purposes.


Top
 Profile  
Reply with quote  
 Post subject: Re: Folder Watcher
PostPosted: Thu Apr 07, 2011 7:15 pm 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
Sub monitorFolder(dir As FolderItem)
//Use soft declares and the A version of this API if you expect to deploy on Windows ME or earlier
Declare Function FindFirstChangeNotificationW Lib "Kernel32" (dirPath As WString, watchChildren As Boolean, eventTypeFilter As Integer) As Integer
Declare Function WaitForSingleObject Lib "Kernel32" (HWND As Integer, waitTime As Integer) As Integer
Declare Function GetLastError Lib "Kernel32" () As Integer

Const FILE_NOTIFY_CHANGE_FILE_NAME = &h00000001 //a file name changed
Const FILE_NOTIFY_CHANGE_DIR_NAME = &h00000002 //a directory name changed
Const FILE_NOTIFY_CHANGE_ATTRIBUTES = &h00000004 //an attribute changed
Const FILE_NOTIFY_CHANGE_SIZE = &h00000008 //Directory size changed
Const FILE_NOTIFY_CHANGE_LAST_WRITE = &h00000010 //the "last write time" changed
Const FILE_NOTIFY_CHANGE_SECURITY = &h00000100 //A security descriptor changed
Const WAIT_ABANDONED = &h00000080
Const WAIT_OBJECT_0 = &h00000000
Const WAIT_TIMEDOUT = &h00000102
Const WAIT_FAILED = &hFFFFFFFF
Const TIMEOUT_INFINITE = &hFFFFFFFF //use this to wait forever, otherwise specify a timeout in milliseconds
Dim allFilters As Integer = FILE_NOTIFY_CHANGE_FILE_NAME Or FILE_NOTIFY_CHANGE_ATTRIBUTES Or FILE_NOTIFY_CHANGE_DIR_NAME Or _
FILE_NOTIFY_CHANGE_LAST_WRITE Or FILE_NOTIFY_CHANGE_SECURITY Or FILE_NOTIFY_CHANGE_SIZE



Dim monitorHandle As Integer = FindFirstChangeNotificationW(dir.AbsolutePath, True, allFilters)
If monitorHandle <> 0 Then
If WaitForSingleObject(monitorHandle, TIMEOUT_INFINITE) <> WAIT_OBJECT_0 Then
Dim err As Integer = GetLastError()
MsgBox("Error Number: " + Str(err) + " On Wait")
Else
//Something changed and we saw it... so do something about it!
Return
End If
Dim err As Integer = GetLastError()
MsgBox("Error Number: " + Str(err) + " On Acquire Handle")
End If


End Sub

_________________
Boredom Software


Top
 Profile  
Reply with quote  
 Post subject: Re: Folder Watcher
PostPosted: Thu Apr 07, 2011 7:24 pm 
Offline
User avatar

Joined: Mon Apr 02, 2007 2:08 am
Posts: 1225
Location: San Francisco, CA, USA
Oh, be warned: the above code will block the entire application until WaitForSingleObject returns.

_________________
Boredom Software


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group