Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Service File date ?

Posted on 2002-05-22
9
Medium Priority
?
145 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 800 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

972 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