was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

91 Visitors Online


 
...das Datum eines Ordners ermitteln/setzen?
Autor: Rainer Kümmerle
Homepage: http://www.thinklazy.de
[ Tip ausdrucken ]  

Tip Bewertung (23):  
     


function GetFolderDate(Folder: string): TDateTime;
var
  
Rec: TSearchRec;
  Found: Integer;
  Date: TDateTime;
begin
  if 
Folder[Length(folder)] = '\' then
    
Delete(Folder, Length(folder), 1);
  Result := 0;
  Found  := FindFirst(Folder, faDirectory, Rec);
  try
    if 
Found = 0 then
    begin
      
Date   := FileDateToDateTime(Rec.Time);
      Result := Date;
    end;
  finally
    
FindClose(Rec);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  
d: TDateTime;
begin
  
d := GetFolderDate('C:\WINNT');
  ShowMessage(FormatDateTime('dddd, d. mmmm yyyy, hh:mm:ss', d));
end;


{ Sets the time for both files and directories }
{ for NT }

function NT_SetDateTime(FileName: string; dtCreation, dtLastAccessTime, dtLastWriteTime: TDateTime): Boolean;
// by Nicholas Robinson
var
  
hDir: THandle;
  ftCreation: TFiletime;
  ftLastAccessTime: TFiletime;
  ftLastWriteTime: TFiletime;

  function DTtoFT(dt: TDateTime): TFiletime;
  var
    
dwft: DWORD;
    ft: TFiletime;
  begin
    
dwft := DateTimeToFileDate(dt);
    DosDateTimeToFileTime(LongRec(dwft).Hi, LongRec(dwft).Lo, ft);
    LocalFileTimeToFileTime(ft, Result);
  end;

begin
  
hDir := CreateFile(PChar(FileName),
                     GENERIC_READ or GENERIC_WRITE,
                     0,
                     nil,
                     OPEN_EXISTING,
                     FILE_FLAG_BACKUP_SEMANTICS,
                     0);
  if hDir <> INVALID_HANDLE_VALUE then 
  begin
    try
      
ftCreation       := DTtoFT(dtCreation);
      ftLastAccessTime := DTtoFT(dtLastAccessTime);
      ftLastWriteTime  := DTtoFT(dtLastWriteTime);
      Result := SetFileTime(hDir, @ftCreation, @ftLastAccessTime, @ftLastWriteTime);
    finally
      
CloseHandle(hDir);
    end;
  end
  else
    
Result := False;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  
NT_SetDateTime('c:\temp\MyFolder', now, now, now);
end;


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners