Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Система";
Текущий архив: 2002.11.04;
Скачать: [xml.tar.bz2];

Вниз

Дата/Время файла   Найти похожие ветки 

 
Avenger   (2002-06-18 08:49) [0]

Как прочитать/изменить дату/время создания/изменения/доступа файла?


 
Севостьянов Игорь   (2002-06-18 11:53) [1]

Простейшие вопросы, господа, как не стыдно так лениться
Ничего захочешь потрудишься...
Вот из RX Lib FileUtil.pas процедура копирования файла, там и найдешь что тебе надо

procedure CopyFileEx(const FileName, DestName: string;
OverwriteReadOnly, ShellDialog: Boolean; ProgressControl: TControl);
var
CopyBuffer: Pointer;
Source, Dest: Integer;
Destination: TFileName;
FSize, BytesCopied, TotalCopied: Longint;
Attr: Integer;
const
ChunkSize: Longint = 8192;
begin
{$IFDEF WIN32}
if NewStyleControls and ShellDialog then begin
CopyMoveFileShell(FileName, DestName, not OverwriteReadOnly,
False, False);
Exit;
end;
{$ENDIF}
Destination := DestName;
if HasAttr(Destination, faDirectory) then
Destination := NormalDir(Destination) + ExtractFileName(FileName);
GetMem(CopyBuffer, ChunkSize);
try
TotalCopied := 0;
FSize := GetFileSize(FileName);
Source := FileOpen(FileName, fmShareDenyWrite); if Source < 0 then
raise EFOpenError.CreateFmt(ResStr(SFOpenError), [FileName]);
try
if ProgressControl <> nil then begin
SetProgressMax(ProgressControl, FSize);
SetProgressMin(ProgressControl, 0);
SetProgressValue(ProgressControl, 0);
end;
ForceDirectories(ExtractFilePath(Destination));
if OverwriteReadOnly then begin
Attr := FileGetAttr(Destination);
if (Attr >= 0) and ((Attr and faReadOnly) <> 0) then
FileSetAttr(Destination, Attr and not faReadOnly);
end;
Dest := FileCreate(Destination); if Dest < 0 then
raise EFCreateError.CreateFmt(ResStr(SFCreateError), [Destination]);
try
repeat
BytesCopied := FileRead(Source, CopyBuffer^, ChunkSize);
if BytesCopied = -1 then
raise EReadError.Create(ResStr(SReadError));
TotalCopied := TotalCopied + BytesCopied;
if BytesCopied > 0 then begin
if FileWrite(Dest, CopyBuffer^, BytesCopied) = -1 then
raise EWriteError.Create(ResStr(SWriteError));
end;
if ProgressControl <> nil then
SetProgressValue(ProgressControl, TotalCopied);
until BytesCopied < ChunkSize;
FileSetDate(Dest, FileGetDate(Source)); finally
FileClose(Dest); end;
finally
FileClose(Source); end;
finally
FreeMem(CopyBuffer, ChunkSize);
if ProgressControl <> nil then
SetProgressValue(ProgressControl, 0);
end;
end;


 
Севостьянов Игорь   (2002-06-18 11:53) [2]

Вот тебе еще

function FileDateTime(const FileName: string): System.TDateTime;
var
Age: Longint;
begin
Age := FileAge(FileName);
if Age = -1 then
Result := NullDate
else
Result := FileDateToDateTime(Age);
end;


 
Севостьянов Игорь   (2002-06-18 11:55) [3]

Или это ... WinAPI

GetFileTime
The GetFileTime function retrieves the date and time that a file was created, last accessed, and last modified.

BOOL GetFileTime(
HANDLE hFile, // handle to file
LPFILETIME lpCreationTime, // creation time
LPFILETIME lpLastAccessTime, // last access time
LPFILETIME lpLastWriteTime // last write time
);
Parameters
hFile
[in] Handle to the files for which to get dates and times. The file handle must have been created with GENERIC_READ access to the file.
lpCreationTime
[out] Pointer to a FILETIME structure to receive the date and time the file was created. This parameter can be NULL if the application does not require this information.
lpLastAccessTime
[out] Pointer to a FILETIME structure to receive the date and time the file was last accessed. The last access time includes the last time the file was written to, read from, or, in the case of executable files, run. This parameter can be NULL if the application does not require this information.
lpLastWriteTime
[out] Pointer to a FILETIME structure to receive the date and time the file was last written to. This parameter can be NULL if the application does not require this information.
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
The FAT and NTFS file systems support the file creation, last access, and last write time values.

Windows NT/2000: If you rename or delete a file, then restore it shortly thereafter, Windows NT searches the cache for file information to restore. Cached information includes its short/long name pair and creation time.

Note Not all file systems can record creation and last access time and not all file systems record them in the same manner. For example, on Windows NT FAT, create time has a resolution of 10 milliseconds, write time has a resolution of 2 seconds, and access time has a resolution of 1 day (really, the access date). On NTFS, access time has a resolution of 1 hour. Therefore, GetFileTime may not return the same file time information set using the SetFileTime function. Furthermore, FAT records times on disk in local time. However, NTFS records times on disk in UTC, so it is not affected by changes in time zone or daylight saving time.

MAPI: For more information, see Syntax and Limitations for Win32 Functions Useful in MAPI Development.

Requirements
Windows NT/2000: Requires Windows NT 3.1 or later.
Windows 95/98: Requires Windows 95 or later.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.

See Also
Time Overview, Time Functions, FILETIME, GetFileSize, GetFileType, SetFileTime



SetFileTime
The SetFileTime function sets the date and time that a file was created, last accessed, or last modified.

BOOL SetFileTime(
HANDLE hFile, // handle to file
CONST FILETIME *lpCreationTime, // creation time
CONST FILETIME *lpLastAccessTime, // last-access time
CONST FILETIME *lpLastWriteTime // last-write time
);
Parameters
hFile
[in] Handle to the file for which to set the dates and times. The file handle must have been created with GENERIC_WRITE access to the file.
lpCreationTime
[in] Pointer to a FILETIME structure that contains the date and time the file was created. This parameter can be NULL if the application does not need to set this information.
lpLastAccessTime
[in] Pointer to a FILETIME structure that contains the date and time the file was last accessed. The last access time includes the last time the file was written to, read from, or (in the case of executable files) run. This parameter can be NULL if the application does not need to set this information.
lpLastWriteTime
[in] Pointer to a FILETIME structure that contains the date and time the file was last written to. This parameter can be NULL if the application does not want to set this information.
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
Not all file systems can record creation and last access time and not all file systems record them in the same manner. For example, on Windows NT FAT, create time has a resolution of 10 milliseconds, write time has a resolution of 2 seconds, and access time has a resolution of 1 day (really, the access date). On NTFS, access time has a resolution of 1 hour. Therefore, the GetFileTime function may not return the same file time information set using SetFileTime. Furthermore, FAT records times on disk in local time. However, NTFS records times on disk in UTC, so it is not affected by changes in time zone or daylight saving time.


 
Robor   (2002-06-18 12:55) [4]

Вот тебе две функции:

Function GetFileTimeMy(FileName:string;Var ftCreation,ftLastAccess,ftLastWrite:TDateTime):boolean;
var {lpftCreation:TFileTime;
lpftLastAccess:TFileTime;
lpftLastWrite:TFileTime;
TempTime:TSystemTime;
hFile:integer;}
fileinfo: TSearchRec;
TempTime:TSystemTime;
begin
result:=(FindFirst(FileName,faAnyFile,fileinfo)=0);
if result then begin
// GetFileTime(hFile,@lpftCreation,@lpftLastAccess,@lpftLastWrite);
FileTimeToSystemTime(FileInfo.FindData.ftCreationTime,TempTime);
ftCreation:=SystemTimeToDateTime(TempTime);
FileTimeToSystemTime(FileInfo.FindData.ftLastAccessTime,TempTime);
ftLastAccess:=SystemTimeToDateTime(TempTime);
FileTimeToSystemTime(FileInfo.FindData.ftLastWriteTime,TempTime);
ftLastWrite:=SystemTimeToDateTime(TempTime)
end;
FindClose(fileinfo);
end;

Function SetFileTimeMy(FileName:string;ftCreation,ftLastAccess,ftLastWrite:TDateTime):boolean;
var
lpftCreation:TFileTime;
lpftLastAccess:TFileTime;
lpftLastWrite:TFileTime;
TempTime:TSystemTime;
hFile:integer;
begin
hFile:=FileOpen(FileName,fmOpenWrite);
result:=(hFile<>-1);
if not result then exit;
DateTimeToSystemTime(ftCreation,TempTime);
SystemTimeToFileTime(TempTime,lpftCreation);
DateTimeToSystemTime(ftLastAccess,TempTime);
SystemTimeToFileTime(TempTime,lpftLastAccess);
DateTimeToSystemTime(ftLastWrite,TempTime);
SystemTimeToFileTime(TempTime,lpftLastWrite);
result:=SetFileTime(hFile,@lpftCreation,@lpftLastAccess,@lpftLastWrite);
FileClose(hFile);
end;


 
Avenger   (2002-06-18 20:48) [5]

Типа круто!


 
Dabus   (2002-08-23 18:35) [6]

Чуваки, вы типа ОХРЕНЕЛИ ! ;)))


 
Овер   (2002-08-24 19:45) [7]

Ух ты.. Буду знать! спасибо!


 
Elmar   (2002-08-28 06:58) [8]

FileSetDate не всегда работает корректно.


 
Redfield   (2002-09-02 18:26) [9]

А как быть с каталогом? Его так

hFile:=FileOpen(FileName,fmOpenWrite);

не откроешь..




Страницы: 1 вся ветка

Форум: "Система";
Текущий архив: 2002.11.04;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.48 MB
Время: 0.008 c
7-11502
VetMIg
2002-08-30 01:59
2002.11.04
Модальные окна


1-11296
Anatoly P
2002-10-23 15:11
2002.11.04
TFileStream и TMemoryStream


14-11393
dogma
2002-10-14 14:17
2002.11.04
База данных или блокнот?


1-11219
nickolayLI
2002-10-24 01:18
2002.11.04
DrawGrid


1-11142
Vaddya
2002-10-23 20:36
2002.11.04
Оператор switch-case





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский