Как изменить дату создания каталога?
Способ первый
function SetDirTime( const Dir: string;
Year, Month, Day, Hour, Minute, Second: Word): boolean;
var
H: integer;
F: TFileTime;
S: TSystemTime;
begin
H := CreateFile( PChar( Dir ), $0100, 0, nil, OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS, 0 );
if H <> -1 then
begin
S.wYear := Year;
S.wMonth := Month;
S.wDay := Day;
S.wHour := Hour;
S.wMinute := Minute;
S.wSecond := Second;
SystemTimeToFileTime( S, F );
LocalFileTimeToFileTime( F, F );
Result := Boolean( SetFileTime( H, @F, @F, @F ) );
CloseHandle( H );
end
else
Result := false;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if not SetDirTime( 'c:\Test', 2011, 1, 1, 12, 0, 0 ) then
ShowMessage( 'Произошла ошибка' );
end; |
Способ второй
function SetDirTime( const Dir: string; DateTime: TDateTime ): boolean;
var
H: integer;
F: TFileTime;
S: TSystemTime;
begin
H := CreateFile( PChar( Dir ), $0100, 0, nil, OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS, 0 );
if H <> -1 then
begin
DateTimeToSystemTime( DateTime, S );
SystemTimeToFileTime( S, F );
LocalFileTimeToFileTime( F, F );
Result := Boolean( SetFileTime( H, @F, @F, @F ) );
CloseHandle( H );
end
else
Result := false;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if not SetDirTime( 'c:\Test', StrToDateTime( '01.01.2011 15:00' ) ) then
ShowMessage( 'Произошла ошибка' );
end; |