Solved

Service File date ?

Posted on 2002-05-22
9
137 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
[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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi IDE crash without error message ... 7 119
drawing animated level bar based on numbers 3 112
PHP preg_replace code convert to Delphi 14 81
IP without any Dots 1 58
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…

733 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