Solved

Service File date ?

Posted on 2002-05-22
9
129 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

706 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now