Service File date ?


I like to create a servie that makes the following thing.

First it should check the modified date on a file.
(say c:\test\file)
Then it should create a directory on another disk with the directory-name set to the modified date-tme of the file.
say d:\backup\2002-05-22:21:30\file for example.
Then the service should wait 10 minutes and then check if
c:\test\file has been modified. If so it should create a new directory with the new modified date-time and create a new copy of the file.

How can I do this?

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.

I've never made a service before, but I tried just then and succeeded - sort of.  The service would only stay in memory for about 20 seconds before closing.

However, the code worked that created the directories.  Here it is:

procedure TDirectoryCreator.Timer1Timer(Sender: TObject);
  hFile, fDate: Integer;
  fDateTime: TDateTime;
  sNewDir: String;
  if not FileExists('C:\temp.txt') then
  Timer1.Enabled := false;
    hFile := FileOpen('C:\temp.txt',  OF_READ);
    fDate := FileGetDate(hFile);
    fDateTime := FileDateToDateTime(fDate);

      sNewDir := 'C:\TEMP\' + FormatDateTime('YYYY-MM-DD-HH-NN-SS', fDateTime);
      if not DirectoryExists(sNewDir) then
    Timer1.Enabled := true;

I'll keep trying this service out.

wqclatreAuthor Commented:
I will try this tonight. One question though.
If I use:
hFile := FileOpen('C:\temp.txt',  OF_READ);

Does this mean that no other application could acces the file when I check the date and make a copy of it?
(I still want other programs to be able to acces and change the file when this server is making a copy of it)

What row in the cod copy the file to sNewDir?

As I wrote I also want to. And where is the check if the file has a newer date-time than the last backup ?
I'm New to delphi so Iäm not sure how to do this.

I'm not 100% sure you can copy a file which is already open by another process.  We can try, but I think it will raise an exception.

I'll change the code for you.  Sorry, I missed the bit about copying the file :)

Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

wqclatreAuthor Commented:
One more question. How do I create the service? On what
property do I put the
procedure TDirectoryCreator.Timer1Timer(Sender: TObject);
Well, when I made the test I gave you, I went to File, New, Server Application.  I then dropped a TTimer onto the form, set its Interval property to 600000 (10 minutes) and ran it.  The problem I had was the service would just terminate itself.  

I've never written one before, so I don't really know how they work or how to install them.  I would imagine it's very easy to do though.


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
wqclatreAuthor Commented:
I think installation is made by:

serverfilename /install
wqclatreAuthor Commented:
I mean serviceFileName /install
wqclatreAuthor Commented:
No idea how to put it all together=?
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept answer from Stuart Johnson

Please leave any comments here within the next seven days.
Paul (pnh73)
EE Cleanup Volunteer
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

From novice to tech pro — start learning today.