bryker
asked on
Change in Dir: Callback for VB5
I need a working example of a VB Callback which executes
upon changes to a directory path which I designate
programmatically beforehand.
In other words, I want to be able to target a directory
path (e.g., "C:\MyApps\MyData\MyDir1")
component which fires anytime a user:
o Copies a file into that directory from another dir,
or creates a file there through other means.
> What are the new file's attributes?
> Name
> Time stamp
> Permissions
> Size
o Renames a file in that directory
> What are the renamed file's attributes?
> Old name (prior to renaming)
> New name (now)
> Time stamp
> Permissions
> Size
o Copies a file in that directory, pastes into same
directory.
> What are the new file's attributes?
> Name
> Time stamp
> Permissions
> Size
o Deletes a file within the specified directory.
> What was the deleted file's name?
This Callback, .BAS, or Class module (I don't care which) MUST FIRE ON THE CHANGE EVENT, not on request from user/developer. The target function (indicating what happened, as outlined above) must fire only when something actually happened in the specified directory. The balance
of the time--while the parent app is loaded--the "listener"
module is doing just that: listening for changes in that directory.
Not to seem unfriendly, but the answer to this non-trivial
question is NOT simply providing the relevant Win32 API
functions
FindFirstChangeNotificatio
and
FindNextChangeNotification
The answer will likely INCLUDE these calls, but the
example providedmust work. I'm giving it 200 points (and perhaps more later) because it requires more than just pointing me to the relevant API calls.
Anyone have ideas on this? Thanks a lot for your help.
bryker@mpsisys.com
ASKER
This does indicate the change event, but only the fact--it doesn't inform of what changed, nor how the subject(s) changed.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To Michelt
In case you haven't noticed, your answer is exactly the same as the one I posted. You took yours from the vbnet website just like me. Also, you'll note that the code does NOT get the attributes of the file that has been changed. Rather, it gets the attributes of the first txt file in the directory. To get the attributes of the file that has been changed, you would have to compare the time/date of all the files in the dir to the current time/date and take whichever is within 1 minute.
Bryker
I have been unable to find a way to do what you want. I'm sure there's a way, it's just that I don't know it.
In case you haven't noticed, your answer is exactly the same as the one I posted. You took yours from the vbnet website just like me. Also, you'll note that the code does NOT get the attributes of the file that has been changed. Rather, it gets the attributes of the first txt file in the directory. To get the attributes of the file that has been changed, you would have to compare the time/date of all the files in the dir to the current time/date and take whichever is within 1 minute.
Bryker
I have been unable to find a way to do what you want. I'm sure there's a way, it's just that I don't know it.
ASKER
Michelt:
Your answer doesn't give me all I want, but I've become convinced that what I want to do is not (feasibly) do-able. I'll give you credit just to close this thing out.
To Spenner
I don't Quite remember Where I got the Code .. It might have been from VBnet or one of the VB programmer's Journals. But that's Totally Besides the point. As for the the File Attributes I was reffering to are returned under
fPath
fName
FileLen(fPath & "\" & fName)
GetAttr(fPath & "\" & fName)
The reason I know this Works is because I use it in one of the Client Server apps. The Only Difference is that The Contents of the Directory Are stored in a Collection To which any and every change is compared.
This way any of the Above Requested Info can be returned. There is also a Count Variable that will know wether or not a File is Added ! This is All Object Oriented in the program and all data is Passes through the properties.
Trust me it works. Itr's the Backend that Drives AS400 to SQL server Updates. Haven't lost a bit of info yet !
I don't Quite remember Where I got the Code .. It might have been from VBnet or one of the VB programmer's Journals. But that's Totally Besides the point. As for the the File Attributes I was reffering to are returned under
fPath
fName
FileLen(fPath & "\" & fName)
GetAttr(fPath & "\" & fName)
The reason I know this Works is because I use it in one of the Client Server apps. The Only Difference is that The Contents of the Directory Are stored in a Collection To which any and every change is compared.
This way any of the Above Requested Info can be returned. There is also a Count Variable that will know wether or not a File is Added ! This is All Object Oriented in the program and all data is Passes through the properties.
Trust me it works. Itr's the Backend that Drives AS400 to SQL server Updates. Haven't lost a bit of info yet !
Fascinating
http://www.mvps.org/vbnet/code/fileapi/watchedfolder.htm
It "watches" a directory and notifies you whenever something occurs in that directory
It also includes code to grab the properties of the newly created file.
I don't know if it will work when you delete a file - but it appears to do everything you want. The reason I don't post it here is because the page also includes a long explanation on the function
While this is kind of "pointing you at the relevant api calls", I think this should answer your question. If not, then reject this answer.