Notification of FileChange

whats the best way of checking to see if a file has been changed? or your probably better off knowing what i am doing...

I am writing a Virtual notice board.. this allowing you to write on it in realtime, allowing up to about 3 people in real time update the board, so in theroy all write on it at the same time, i have a dedicated server for this, should i use text files or delph 4's  built in TCP IP stuff?? ay suggestions?
LVL 2
craig_capelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TheNeilCommented:
Well you'll ned to keep a record of the time/date stamp of each of the files, and then all you need to do is compare the stored value with the current value. You can do this really simply just by using a flat ASCII file database

The Neil
0
AttarSoftwareCommented:
If you go to :

http://www.itecuk.com/delmag/index.htm

and download this months companion disk, there is a Taming The File System feature, in which he does exactly this using the API...

<Snip>
Beating the System: Taming The File System, 3
Dave Jewell continues building his Windows file system object, this month adding in support for file change notifications before calling it a day
</Snip>

Good luck...

Tim.
0
wmckieCommented:
Would the FindFirstChangeNotification and FindNextChangeNotification API's be appropriate? There have been discussions on these recently in Delphi Informant and The Delphi Magazine also the RX suite has a TRxFolderMonitor component. I've not used the component or the API but it might help.

Cheers - Walter McKie
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

AttarSoftwareCommented:
Heh, yup, my link was for the Delphi Magazine ;O)

And he does use the FindFirstChangeNotification calls (if I remember correctly...I was too busy reading the encryption chapter...) ;O)

Tim.
0
craig_capelAuthor Commented:
I was actually going to get the size of the exe every second, and see if the file changes in size,... getfilesize, and the delphi proc says i can not use it on txt files...


Checking Links Out Now :) thanks all.... brb
0
ptmcompCommented:
I had lot of troubles comparing file time stamps of the client and the server. They were not rounded the same way so I had always a diffrence and while switching on summer time one was an hour older 'cause the server has an radio clock which just changes the time without saying that it's summer time. So UTC becames usless #:-{ .
0
intheCommented:
listening..
0
craig_capelAuthor Commented:
ok then.... not much help, would it not be easier for me just to see if the file size increases and if it does catch it?....

or move over to TCP / IP and use the server with a server to client(s) program sitting on it? Seen many chat programs, but the problem with them is once you logged on it starts from fresh, but pretty useless, i want it to be there all day, i want to know the best way of doing this....

Thanks All....

P.S Barry, in EE , what exatly does "Listening" mean? is a way of saying, come on get what you mean out? or what....
0
AttarSoftwareCommented:
Did that "Taming the filesystem" thing not help?  I am sure that had the notification calls you needed (but as I said, I only skim read the article)

Tim.

PS:  Listening means that Barry does not have to pay points to see this question when an answer has been accepted, as he was a contributor ;O)
0
intheCommented:
no it means im waiting to see if you request example of findfirstfilenotification() and if so then i'll paste a good one here .. ;-)

putting the word "listening.." is more polite than just leaving a blank comment ,it also means i can see the answer if someone answers it while im out...

for this question my suggestion would certainly be to use the FindFirstChangeNotification but someone else mentioned it already ..
0
intheCommented:
hello tim
got it in one ;-)
0
intheCommented:
here is another example:
{remember tim mentioned it first i just have this example handy so dont accept as answer}

unit FileNTU;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, Buttons, FileCtrl, Menus, ComCtrls;

type
  TForm1 = class(TForm)
    DriveComboBox1: TDriveComboBox;
    DirectoryListBox1: TDirectoryListBox;
    FileListBox1: TFileListBox;
    StatusBar1: TStatusBar;
    Button1: TButton;
    Memo1: TMemo;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  protected
  end;

var
  Form1: TForm1;
  NotificationHandle: THandle;    // holds the handle to the notification object

implementation

{$R *.DFM}

procedure TForm1.Button2Click(Sender: TObject);
begin
  {establish a notification for file size changes on the selected directory}
  NotificationHandle := FindFirstChangeNotification(PChar(DirectoryListBox1.
                                                  Directory), FALSE,
                                                  FILE_NOTIFY_CHANGE_SIZE);

  {if the notification was set up correctly, modify some UI elements...}
  if (NotificationHandle <> INVALID_HANDLE_VALUE) then
  begin
    Button1.Enabled := TRUE;
    Button2.Enabled := FALSE;
  end
  else
  begin
    {...otherwise indicate that there was an error}
    ShowMessage('There was an error setting the notification');
    Exit;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  dwResult: DWORD;         // holds the result of waiting on the notification
  Waiting: Boolean;        // loop control variable
begin
  {setup the loop control for a continuous loop}
  Waiting := TRUE;

  {indicate that the application is waiting for the change notification to fire}
  Button1.Enabled := FALSE;
  StatusBar1.SimpleText := 'Now waiting for a filesize change';
  Application.ProcessMessages;

  {enter the loop}
  while Waiting do
  begin
    {at this point, the application is suspended until the notification
     object is signaled that a filename change has occured in the
     selected directory (this includes file deletions)}
    dwResult := WaitForSingleObject(NotificationHandle,INFINITE);
    if (dwResult = WAIT_OBJECT_0) then
    begin
      {indicate that the notification object was signaled}
      ShowMessage('The selected directory signaled a filesize change');

      {query the user to see if they wish to continue monitoring this
       directory}
      if Application.MessageBox('Do you wish to continue monitoring this directory?',
                 'Continue?', MB_ICONQUESTION or MB_YESNO) = IDYES then
        {if the user wishes to continue monitoring the directory, reset
         the notification object and continue the loop...}
        FindNextChangeNotification(NotificationHandle)
      else
        {...otherwise break out of the loop}
        Waiting := FALSE;
    end;
  end;

  {close the notification object}
  FindCloseChangeNotification(NotificationHandle);

  {reset UI elements}
  Button1.Enabled := FALSE;
  Button2.Enabled := TRUE;
  StatusBar1.SimpleText := '';
  FileListBox1.Update;
end;

end.
0
craig_capelAuthor Commented:
Ah i see.... Good damage limitation Barry :) yes ok then, FindFirstChangeNotification it will have to be.....

Do i need a hook to do this?
0
craig_capelAuthor Commented:
oh great, half way through my question, the phone rings, and Barry starts to feel guilty about posting "Listening" and posts code to me :)

Right, i have put the phone off the hook for this :)
0
AttarSoftwareCommented:
;O)
0
craig_capelAuthor Commented:
OK Barry, you want me to test this code out... but if i find that ok works.... what do i do? shall ignore your comment and give you the points anyhow... its probably the best answer i am going to get...


Stuck what do i do?
0
craig_capelAuthor Commented:
How about this... 60 points is not a lot, but is all i can afford until my boss gets my NIF / CIF number so i can get a Credit Card.....

hmm, Shall i Delete the question, and give 30 out to both of you, or what.... now i'm the one feeling guilty.....
0
AttarSoftwareCommented:
Go on, give them to Barry =O)

It will help keep him at the top, top, top, top, top of the league...

Tim. (miles away from the lowest of all free t-shirts) ;O)
0
intheCommented:
hi craig no hook involved here ;-)
if its easier i send you the demo project for this,just say if you need it
(and leave mail address i keep forgetting to save them.)

Regards The Guilty One :o)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
craig_capelAuthor Commented:
Tim, i feel bad about this... If i leave you my password... will you give him the points... no win situation...  


Well,i have no choice but to give the points to someone.... so tim please forgive me :)
0
AttarSoftwareCommented:
Consider it done =O)

Tim
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.