Solved

Service File date ?

Posted on 2002-05-22
9
136 Views
Last Modified: 2010-04-04
Hi!

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?

0
Comment
Question by:wqclatre
  • 5
  • 3
9 Comments
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 7028850
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);
var
  hFile, fDate: Integer;
  fDateTime: TDateTime;
  sNewDir: String;
begin
  if not FileExists('C:\temp.txt') then
    Exit;
  Timer1.Enabled := false;
  try
    hFile := FileOpen('C:\temp.txt',  OF_READ);
    fDate := FileGetDate(hFile);
    fDateTime := FileDateToDateTime(fDate);

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

I'll keep trying this service out.

Stu
0
 
LVL 2

Author Comment

by:wqclatre
ID: 7029009
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.
 
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 7029029
Hi,

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 :)

Stu
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 2

Author Comment

by:wqclatre
ID: 7029042
One more question. How do I create the service? On what
property do I put the
procedure TDirectoryCreator.Timer1Timer(Sender: TObject);
0
 
LVL 6

Accepted Solution

by:
Stuart_Johnson earned 200 total points
ID: 7029050
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.

Stu
0
 
LVL 2

Author Comment

by:wqclatre
ID: 7029144
I think installation is made by:

serverfilename /install
0
 
LVL 2

Author Comment

by:wqclatre
ID: 7029145
I mean serviceFileName /install
0
 
LVL 2

Author Comment

by:wqclatre
ID: 7130687
No idea how to put it all together=?
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9006700
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.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

860 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