Previous Thread
Next Thread
Print Thread
Joined: Sep 2006
Posts: 14,248
Legend
OP Offline
Legend
Joined: Sep 2006
Posts: 14,248
Figured I'd ask here before going to a technical forum ... Is anyone here familiar with using Task Scheduler within Windows? I'd like to be able to trigger an event whenever a specific file in a directory is modified. I've seen mentions that something like this may be possible, but no actual example.

Joined: Oct 2006
Posts: 2,032
Y
Dawg Talker
Offline
Dawg Talker
Y
Joined: Oct 2006
Posts: 2,032
Think you need to write a service to do that.


#gmstrong
Joined: Sep 2006
Posts: 28,363
Legend
Offline
Legend
Joined: Sep 2006
Posts: 28,363
All you would need to do is write some form of script that checks the desired path and does whatever you want it to do if it finds what it is looking for.
Whether you use DOS Batch, PHP, or even Perl matters not.... just run whatever it is via command line (e.g. c:\php\php.exe c:\folderWatcher.php).

Then, simply set it up as a standard scheduled task and use an Advanced Schedule to set it to run once every minute.



If you need it to run more frequently than once per minute... e.g. asynchronously always watching a folder, then I'd suggest digging into .NET a bit, and toying with writing a simple service that makes use of a FileSystemWatcher object. Or, you can just write a simple EXE that launches as a startup item, and set up a simple timer whose Tick() event calls the function that checks the path and does the work... or you could even have the EXE make use of the FileSystemWatcher.


Browns is the Browns

... there goes Joe Thomas, the best there ever was in this game.

Joined: Sep 2006
Posts: 14,248
Legend
OP Offline
Legend
Joined: Sep 2006
Posts: 14,248
Thanks Purp. I think a DOS Batch will do the job, and a one minute timer should be plenty sufficient. I haven't exactly written a DOS Batch before, but I've done quite a bit in Unix scripting, so hopefully it's not too different. I should be able to Google much of what I think I need to do, so I'll let you know directly if I have any issues.

Thanks again!

Joined: Sep 2006
Posts: 15,015
F
Legend
Offline
Legend
F
Joined: Sep 2006
Posts: 15,015
My only problem with once a minute is it becomes taxing on the system. If you can go every 5-10 minutes would be significantly better for the system.

There are also little programs like this:
http://www.tawbaware.com/filemon.htm

Last edited by FloridaFan; 07/29/10 07:41 AM.

We don't have to agree with each other, to respect each others opinion.
Joined: Sep 2006
Posts: 28,363
Legend
Offline
Legend
Joined: Sep 2006
Posts: 28,363
oh, once per minute is nothing..... all you need to do is have it fire off and exit immediately if conditions aren't met.

The biggest annoyance is that it will pop open a DOS box while it runs.


If you've written Unix scripts, you should be fine with DOS Batch. Same concepts, just different command names.





****NOTE on using SCHEDULER vs. a SERVICE: Depending on your OS, your scheduled task will NOT run at all unless the account you specify for the task is currently logged into the machine at the console. For this reason, a service may be the better solution. Fortunately, you do not need to know how to write a service. You can use a program such as Firedaemon to run a process as a service, or, if you have an executable, you can make use of InstSrv to add any application as a service.


Browns is the Browns

... there goes Joe Thomas, the best there ever was in this game.

Joined: Sep 2006
Posts: 14,248
Legend
OP Offline
Legend
Joined: Sep 2006
Posts: 14,248
I'm using Win 7 ... I think Scheduler there now has the option to both run as Admin (which likely creates a service) and also allows it to run in the background. I'll try playing around with this stuff later today.

Joined: Sep 2006
Posts: 50,931
Legend
Offline
Legend
Joined: Sep 2006
Posts: 50,931
Win 7 looks to have a pretty straight forward setup for tasks. If you go to Task Scheduler, then Create Task, the go to Triggers, New, and then use "On task creation/modification from the drop down, can you set it up from there?


Micah 6:8; He has shown you, O mortal, what is good. And what does the Lord require of you? To act justly and to love mercy, and to walk humbly with your God.

John 14:19 Jesus said: Because I live, you also will live.
Joined: Sep 2006
Posts: 14,248
Legend
OP Offline
Legend
Joined: Sep 2006
Posts: 14,248
Yeah, scheduling based on time is easy. It's the whole on-event trigger that has me at a loop.

Joined: Sep 2006
Posts: 28,363
Legend
Offline
Legend
Joined: Sep 2006
Posts: 28,363
You're not doing in onEvent. Simply write the script to do what you need it to do if a condition is met... i.e. the file has changed.

So, you're more of a polling model than an event driven one.

All you need is some way of storing the "old" state of the file.... which you can do in a text file.



Better yet, tell me what it is you are wanting to do, precisely, and I'll see if I can mock up some form of example code.


Browns is the Browns

... there goes Joe Thomas, the best there ever was in this game.

Joined: Sep 2006
Posts: 14,248
Legend
OP Offline
Legend
Joined: Sep 2006
Posts: 14,248
Well I looked at Batch scripting, and that looked limited (as well as over my head). I was able to figure out the same thing in a vbscript, which I think I'll be able to call with the scheduler as well and do the same thing.

Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFolder = "C:\test"
dstFolder = "C:\test\test2"
Set objFolder = objFSO.GetFolder(strFolder)
For Each strFiles In objFolder.Files
If DateDiff("n",strFiles.DateLastModified,Now) < 15 Then
objFSO.CopyFile strFiles.Name, dstFolder & "\" & strFiles.Name
End If
Next


Joined: Sep 2006
Posts: 28,363
Legend
Offline
Legend
Joined: Sep 2006
Posts: 28,363
To do that script in Batch would have required a 3rd party utility just to get date modified.

What you have there will work as well as anything, you'll just have to be logged in to have it run, which isn't a big deal.


Browns is the Browns

... there goes Joe Thomas, the best there ever was in this game.

DawgTalkers.net Forums DawgTalk Tailgate Forum Anybody here familiar with Windows Task Scheduler?

Link Copied to Clipboard
Powered by UBB.threads™ PHP Forum Software 7.7.5