Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Send signals to each user using same system
Message
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01293566
Message ID:
01294229
Views:
24
Here is another option. Uses WMI. I found this back in September and saved the link:

http://www.themssforum.com/ExchangeFox/File-exists/

Courtesy of Roger, but I don't know who Roger is.

To test it, make sure you have a directory c:\temp. Run the code from a command window in VFP and while it is running, jump to a command prompt in a dos window and create a file in c:\temp (or you can use windows explorer).
*--Courtesy of Roger at http://www.themssforum.com/ExchangeFox/File-exists/
*

*--Hit Escape to cancel. - Monitors c:\temp

******************* 
* FolderWatcher.prg 
******************* 
Local x, lcWQL, lcComputer, loSinkEvents, loEvent 
Local loSink 
Set Escape On 
On Key Label ESC Clear Events 

Clear 
lcComputer = "." 

*change the line below to your "watched" folder 
*and yes you need 4 backslashes! 
lcFolderToWatch = "c:\\\\temp" 

loWMI = Getobject("winmgmts:" ; 
+ "{impersonationLevel=impersonate}!\\" + ; 
lcComputer + ; 
"\root\cimv2") 

lcWQL = "" 

* Change the "Within 2" to how often you want 
* to poll for new files (in seconds) 
Text to lcWQL Textmerge NoShow Pretext 7 
Select * From __InstanceCreationEvent Within 2 
Where TargetInstance ISA 'CIM_DirectoryContainsFile' 
And TargetInstance.GroupComponent = 
'Win32_Directory.Name="<<lcFolderToWatch>>"' 
EndText 

loSinkEvents=Newobject("myEventHandler") 
loSink = Createobject("WbemScripting.SWbemSink","SINK_") 
Eventhandler(loSink,loSinkEvents) 

loWMI.ExecNotificationQueryAsync(loSink,lcWQL) 

READ EVENTS 

On Key Label ESC 

Define Class myEventHandler As Session 
Implements ISWbemSinkEvents In ; 
"C:\WINDOWS\SYSTEM32\WBEM\WBEMDISP.TLB" 
Procedure ISWbemSinkEvents_OnObjectReady(; 
objWbemObject As VARIANT,; 
objWbemAsyncContext As VARIANT); 
As VOID; 
HelpString "Event triggered when an Object is available" 
? objWbemObject.TargetInstance.PartComponent 
Endproc 

Procedure ISWbemSinkEvents_OnCompleted(; 
iHResult As VARIANT,; 
objWbemErrorObject As VARIANT,; 
objWbemAsyncContext As VARIANT); 
As VOID; 
HelpString "Event triggered when an asynchronous operation is completed" 
* add user code here 
Endproc 

Procedure ISWbemSinkEvents_OnProgress(; 
iUpperBound As Number,; 
iCurrent As Number,; 
strMessage As String,; 
objWbemAsyncContext As VARIANT); 
As VOID; 
HelpString "Event triggered to report the progress of an asynchronous operation" 
* add user code here 
Endproc 

Procedure ISWbemSinkEvents_OnObjectPut(; 
objWbemObjectPath As VARIANT,; 
objWbemAsyncContext As VARIANT); 
As VOID; 
HelpString "Event triggered when an object path is available following a Put operation" 
* add user code here 
Endproc 
EndDefine 

* End prg 
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Reply
Map
View

Click here to load this message in the networking platform