?
Solved

How to change a file's date/time ?

Posted on 2000-02-12
1
Medium Priority
?
191 Views
Last Modified: 2010-04-04
I want to change the date/time of a file and tried it with the following code.
At run-time the error "invalid variant type conversion" occurs.
It has to do with the conversion of the filename-string, but I have no idea
what to change. Can anyone help me ?

Thanks in advance,
Tulip

var handle : THandle;
    ft : TFileTime;
    dt : TDateTime;
    st : TSystemTime;
    filename : String;
begin
  filename := 'C:\temp\test.txt';
  dt := EncodeDate(1999, 1, 1);
  dt := dt + EncodeTime(17, 30, 0, 0);
  DateTimeToSystemTime(dt, st);
  SystemTimeToFileTime(st, ft);
  handle := CreateFile(PChar(filename), GENERIC_WRITE, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  SetFileTime(handle, nil, nil, @ft);
  CloseHandle(handle);
end;
0
Comment
Question by:Tulip
1 Comment
 
LVL 1

Accepted Solution

by:
XAN earned 200 total points
ID: 2514790
well, it's code correct executes on my computer (WindowsNT) - 0 (zero), not NULL

var
  handle : THandle;
  ft : TFileTime;
  dt : TDateTime;
  st : TSystemTime;
  filename : String;
begin
  filename := 'C:\temp\test.txt';
  dt := EncodeDate(1999, 1, 1);
  dt := dt + EncodeTime(17, 30, 0, 0);
  DateTimeToSystemTime(dt, st);
  SystemTimeToFileTime(st, ft);
  handle := CreateFile(PChar(filename), GENERIC_WRITE, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  SetFileTime(handle, nil, nil, @ft);
  CloseHandle(handle);

Good luck :)
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Question has a verified solution.

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

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…
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…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Suggested Courses
Course of the Month6 days, 20 hours left to enroll

593 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