Solved

Checking a folder all the time

Posted on 2001-06-27
5
151 Views
Last Modified: 2010-05-02
I would like to make a program always checking a folder in server. If someone write a file into the folder, it would cut & paste to another folder immediately.

I've heard that using a service to run the job when server starts. Is that right? How to do? Any other suggestion?
0
Comment
Question by:neltan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 6230513
neltan, there are two parts to this. One yes is that you should run the application as a service, the other is that you should use the FindFirstChangeNotification api call to watch the specified folder for changes, this the api that windows itself uses to identify changes to files/folders.

Here is a starter sample for the findfirstchangenotification:

Private Const FILE_NOTIFY_CHANGE_ATTRIBUTES = &H4
Private Const FILE_NOTIFY_CHANGE_DIR_NAME = &H2
Private Const FILE_NOTIFY_CHANGE_FILE_NAME = &H1
Private Const FILE_NOTIFY_CHANGE_SIZE = &H8
Private Const FILE_NOTIFY_CHANGE_LAST_WRITE = &H10
Private Const FILE_NOTIFY_CHANGE_SECURITY = &H100
Private Const FILE_NOTIFY_CHANGE_ALL = &H4 Or &H2 Or &H1 Or &H8 Or &H10 Or &H100
Private Declare Function FindFirstChangeNotification Lib "kernel32" Alias "FindFirstChangeNotificationA" (ByVal lpPathName As String, ByVal bWatchSubtree As Long, ByVal dwNotifyFilter As Long) As Long
Private Declare Function FindCloseChangeNotification Lib "kernel32" (ByVal hChangeHandle As Long) As Long
Private Declare Function FindNextChangeNotification Lib "kernel32" (ByVal hChangeHandle As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function ResetEvent Lib "kernel32" (ByVal hEvent As Long) As Long
Private Sub Form_Load()
    'KPD-Team 2000
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net
    Dim Ret As Long
    'Set the notification hook
    Ret = FindFirstChangeNotification("C:\", &HFFFFFFFF, FILE_NOTIFY_CHANGE_ALL)
    'Wait until the event is triggered
    WaitForSingleObject Ret, &HFFFFFFFF
    MsgBox "Event Triggered for the first time"
    'Reactivate our hook
    FindNextChangeNotification Ret
    'Wait until the event is triggered
    WaitForSingleObject Ret, &HFFFFFFFF
    MsgBox "Event Triggered for the second time"
    'Remove our hook
    FindCloseChangeNotification Ret
End Sub

You will need to modify this to copy the referenced file using its file handle.
0
 

Author Comment

by:neltan
ID: 6230533
Would you please explain your program briefly? I cannot understand.
0
 

Author Comment

by:neltan
ID: 6230641
Or How can I create a exe or dll which will be run by service?
0
 
LVL 28

Accepted Solution

by:
Ark earned 50 total points
ID: 6230696
Take a look at http://www.mvps.org/vbnet/code/fileapi/watchedfolder.htm
for explanation and sample code.

Cheers
0
 

Author Comment

by:neltan
ID: 6234318
Thank you everyone!
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question