mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-02 23:10:28 +02:00
* FileSetDate with TDateTime and UTC for file names
git-svn-id: trunk@47398 -
This commit is contained in:
parent
3ea339400e
commit
8ce015535a
@ -338,6 +338,16 @@ begin
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
Function FileSetDate (Const FileName : RawByteString;const FileDateTime : TDateTime) : Longint;
|
||||
begin
|
||||
Result:=FileSetDate(UnicodeString(FileName),FileDateTime);
|
||||
end;
|
||||
|
||||
Function FileSetDateUTC (Const FileName : RawByteString;const FileDateTimeUTC : TDateTime) : Longint;
|
||||
begin
|
||||
Result:=FileSetDateUTC(UnicodeString(FileName),FileDateTimeUTC);
|
||||
end;
|
||||
|
||||
|
||||
function FileAge(const FileName: UnicodeString; out FileDateTime: TDateTime; FollowLink: Boolean = True): Boolean;
|
||||
Var
|
||||
@ -843,15 +853,25 @@ begin
|
||||
FileDateTimeUTC:=FileDateToUniversal(aDate);
|
||||
end;
|
||||
|
||||
Function FileSetDate (Handle : THandle; const Age: TDateTime) : Longint;
|
||||
Function FileSetDate (Handle : THandle; const FileDateTime: TDateTime) : Longint;
|
||||
begin
|
||||
Result := FileSetDate(Handle,DateTimeToFileDate(Age));
|
||||
Result := FileSetDate(Handle,DateTimeToFileDate(FileDateTime));
|
||||
end;
|
||||
|
||||
Function FileSetDateUTC (Handle : THandle; const AgeUTC: TDateTime) : Longint;
|
||||
Function FileSetDateUTC (Handle : THandle; const FileDateTimeUTC: TDateTime) : Longint;
|
||||
begin
|
||||
Result := FileSetDate(Handle,UniversalToFileDate(AgeUTC));
|
||||
Result := FileSetDate(Handle,UniversalToFileDate(FileDateTimeUTC));
|
||||
end;
|
||||
|
||||
|
||||
Function FileSetDate (Const FileName : UnicodeString;const FileDateTime : TDateTime) : Longint;
|
||||
begin
|
||||
Result:=FileSetDate(FileName,DateTimeToFileDate(FileDateTime));
|
||||
end;
|
||||
|
||||
Function FileSetDateUTC (Const FileName : UnicodeString;const FileDateTimeUTC : TDateTime) : Longint;
|
||||
begin
|
||||
Result:=FileSetDate(FileName,UniversalToFileDate(FileDateTimeUTC));
|
||||
end;
|
||||
|
||||
{$ENDIF}
|
||||
|
@ -182,6 +182,8 @@ Function FileAge (Const FileName : UnicodeString): Int64;
|
||||
Function FileExists (Const FileName : UnicodeString; FollowLink : Boolean = True) : Boolean;
|
||||
Function DirectoryExists (Const Directory : UnicodeString; FollowLink : Boolean = True) : Boolean;
|
||||
Function FileSetDate (Const FileName : UnicodeString;Age : Int64) : Longint;
|
||||
Function FileSetDate (Const FileName : UnicodeString;const FileDateTime : TDateTime) : Longint;
|
||||
Function FileSetDateUTC (Const FileName : UnicodeString;const FileDateTimeUTC : TDateTime) : Longint;
|
||||
Function FileGetAttr (Const FileName : UnicodeString) : Longint;
|
||||
Function FileSetAttr (Const Filename : UnicodeString; Attr: longint) : Longint;
|
||||
Function DeleteFile (Const FileName : UnicodeString) : Boolean;
|
||||
@ -205,6 +207,8 @@ Function FileCreate (Const FileName : RawByteString; ShareMode : Integer; Rights
|
||||
Function FileExists (Const FileName : RawByteString; FollowLink : Boolean = True) : Boolean;
|
||||
Function DirectoryExists (Const Directory : RawByteString; FollowLink: Boolean = True) : Boolean;
|
||||
Function FileSetDate (Const FileName : RawByteString;Age : Int64) : Longint;
|
||||
Function FileSetDate (Const FileName : RawByteString;const FileDateTime : TDateTime) : Longint;
|
||||
Function FileSetDateUTC (Const FileName : RawByteString;const FileDateTimeUTC : TDateTime) : Longint;
|
||||
Function FileGetAttr (Const FileName : RawByteString) : Longint;
|
||||
Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
|
||||
Function DeleteFile (Const FileName : RawByteString) : Boolean;
|
||||
@ -235,8 +239,8 @@ Function FileGetDate (Handle : THandle) : Int64;
|
||||
Function FileGetDate (Handle : THandle; out FileDateTime: TDateTime) : Boolean;
|
||||
Function FileGetDateUTC (Handle : THandle; out FileDateTimeUTC: TDateTime) : Boolean;
|
||||
Function FileSetDate (Handle : THandle;Age : Int64) : Longint;
|
||||
Function FileSetDate (Handle : THandle; const Age: TDateTime) : Longint;
|
||||
Function FileSetDateUTC (Handle : THandle; const AgeUTC: TDateTime) : Longint;
|
||||
Function FileSetDate (Handle : THandle; const FileDateTime: TDateTime) : Longint;
|
||||
Function FileSetDateUTC (Handle : THandle; const FileDateTimeUTC: TDateTime) : Longint;
|
||||
Function GetFileHandle(var f : File):THandle;
|
||||
Function GetFileHandle(var f : Text):THandle;
|
||||
|
||||
|
@ -694,13 +694,13 @@ begin
|
||||
Result := GetLastError;
|
||||
end;
|
||||
|
||||
Function FileSetDate (Handle : THandle; const Age: TDateTime) : Longint;
|
||||
Function FileSetDate (Handle : THandle; const FileDateTime: TDateTime) : Longint;
|
||||
var
|
||||
FT: TFiletime;
|
||||
LT: TFiletime;
|
||||
ST: TSystemTime;
|
||||
begin
|
||||
DateTimeToSystemTime(Age,ST);
|
||||
DateTimeToSystemTime(FileDateTime,ST);
|
||||
if SystemTimeToFileTime(ST,LT) and LocalFileTimeToFileTime(LT,FT)
|
||||
and SetFileTime(Handle,nil,nil,@FT) then
|
||||
Result:=0
|
||||
@ -708,12 +708,12 @@ begin
|
||||
Result:=GetLastError;
|
||||
end;
|
||||
|
||||
Function FileSetDateUTC (Handle : THandle; const AgeUTC: TDateTime) : Longint;
|
||||
Function FileSetDateUTC (Handle : THandle; const FileDateTimeUTC: TDateTime) : Longint;
|
||||
var
|
||||
FT: TFiletime;
|
||||
ST: TSystemTime;
|
||||
begin
|
||||
DateTimeToSystemTime(AgeUTC,ST);
|
||||
DateTimeToSystemTime(FileDateTimeUTC,ST);
|
||||
if SystemTimeToFileTime(ST,FT) and SetFileTime(Handle,nil,nil,@FT) then
|
||||
Result:=0
|
||||
else
|
||||
@ -737,6 +737,40 @@ begin
|
||||
else
|
||||
Result:=GetLastOSError;
|
||||
end;
|
||||
|
||||
Function FileSetDate (Const FileName : UnicodeString;const FileDateTime : TDateTime) : Longint;
|
||||
Var
|
||||
fd : THandle;
|
||||
begin
|
||||
FD := CreateFileW (PWideChar (FileName), GENERIC_READ or GENERIC_WRITE,
|
||||
FILE_SHARE_WRITE, nil, OPEN_EXISTING,
|
||||
FILE_FLAG_BACKUP_SEMANTICS, 0);
|
||||
If (Fd<>feInvalidHandle) then
|
||||
try
|
||||
Result:=FileSetDate(fd,FileDateTime);
|
||||
finally
|
||||
FileClose(fd);
|
||||
end
|
||||
else
|
||||
Result:=GetLastOSError;
|
||||
end;
|
||||
|
||||
Function FileSetDateUTC (Const FileName : UnicodeString;const FileDateTimeUTC : TDateTime) : Longint;
|
||||
Var
|
||||
fd : THandle;
|
||||
begin
|
||||
FD := CreateFileW (PWideChar (FileName), GENERIC_READ or GENERIC_WRITE,
|
||||
FILE_SHARE_WRITE, nil, OPEN_EXISTING,
|
||||
FILE_FLAG_BACKUP_SEMANTICS, 0);
|
||||
If (Fd<>feInvalidHandle) then
|
||||
try
|
||||
Result:=FileSetDateUTC(fd,FileDateTimeUTC);
|
||||
finally
|
||||
FileClose(fd);
|
||||
end
|
||||
else
|
||||
Result:=GetLastOSError;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
Function FileGetAttr (Const FileName : UnicodeString) : Longint;
|
||||
|
Loading…
Reference in New Issue
Block a user