Link to home
Create AccountLog in
Avatar of Camillia
CamilliaFlag for United States of America

asked on

What type of project i need for filesystemwatcher

I'm trying to write a code that uses filesystemwatcher. Looking for examples but not sure what type of project this goes into? not a web app...i doubt. Has to be something like winform??
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Camillia

ASKER

yes, you gave me that link. I totally forgot. I need to check for file named "PX.txt" or PXDelta.txt". Import them and then rename that file...rename it for example by attaching datatime to the end...

Reading this http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx


I need to use NotifyFilters.FileName ?
>>you gave me that link

Sorry, I never look at the name of the question asker.

>>I need to check for file named "PX.txt" or PXDelta.txt"

Check my example. You need to set the .Filter property to "PX*.txt" and you also need to handle the created event.
i'll keep this question open for one or 2 more days. Thanks
ok, this is what i need to do:
1. there are 6 files i need to monitor PX.txt, PXDelta.txt, NX.txt,NXDelta.txt, WAR.txt and WARDelta.txt ... this is done with .Filter property?
2. Parse the file name: see if it has "delta" in it or not and also get the name "px or nx or war" Not sure how to do this
3. If they're in the folder, I will call a stored proc (i know how to do this)
4. Rename the files with datatime at the end.

How can I do #1 and #2?
why don't you use .Filter = "*.txt" and in the Created event handler use a switch statement for your filename pattern (ignoring all other that are not corresponding)?
So this takes care of #1.
Then for #2...use that Switch statement to get the file name (i think that's correct, no?)
#2 use the filename received in the Created event to switch against your PX, PXDelta, NX, ...
not sure what that means but i will for examples
in your Create event handler

if e.FullPath.Contains("PX.txt") then
   'do something for PX file
elseif e.FullPath.Contains("PXDelta.txt") then
   'do something for PXDelta file
...
end if
ah, yes, thanks. I will try and post back
Can I schedule a windows form application??
Sure you. But why would you schedule it if the watcher is constantly checking?
hmm...so i just leave the app open on the server if i dont schedule it? Maybe "scheudle" is the wrong word. I need the app to keep checking. It has a form interface. Just leave that form open on the server??
yes just leave it running
i will unless my manager tells me no :)