PDA

View Full Version : بدست آوردن تاریخ ایجاد فایل



fahimi
جمعه 12 دی 1382, 05:25 صبح
با سلام خدمات دوستان
در دلفی چگونه می توان تاریخ ایجاد فایل را بدست آورد

omidsm
جمعه 12 دی 1382, 12:43 عصر
procedure TFMForm.Properties1Click(Sender: TObject);
var
Attributes, NewAttributes: Word;
begin
with FileAttrForm do
begin
FileDirName.Caption := FileList.Items[FileList.ItemIndex];
{ set box caption }
PathName.Caption := FileList.Directory;
{ show directory name }
ChangeDate.Caption :=
DateTimeToStr(FileDateToDateTime(FileAge(FileList. FileName)));
Attributes := FileGetAttr(FileDirName.Caption);
{ read file attributes }
ReadOnly.Checked := (Attributes and faReadOnly) = faReadOnly;
Archive.Checked := (Attributes and faArchive) = faArchive;
System.Checked := (Attributes and faSysFile) = faSysFile;
Hidden.Checked := (Attributes and faHidden) = faHidden;
if ShowModal <> id_Cancel then { execute dialog box }
begin
NewAttributes := Attributes;
{ start with original attributes }
if ReadOnly.Checked then
NewAttributes := NewAttributes or faReadOnly
else
NewAttributes := NewAttributes andnot faReadOnly;
if Archive.Checked then
NewAttributes := NewAttributes or faArchive
else
NewAttributes := NewAttributes andnot faArchive;
if System.Checked then
NewAttributes := NewAttributes or faSysFile
else
NewAttributes := NewAttributes andnot faSysFile;
if Hidden.Checked then
NewAttributes := NewAttributes or faHidden
else
NewAttributes := NewAttributes andnot faHidden;
if NewAttributes <> Attributes then { if anything changed... }
FileSetAttr(FileDirName.Caption, NewAttributes);
{ ...write the new values }
end;
end;
end;
تو هلپ دلفی دنبال FileAge بگرد

SReza1
جمعه 12 دی 1382, 13:16 عصر
اینم جواب مختصر مفید!!! زمان ایجاد فایل در caption فرم ظاهر میشه! زمان اخرین دسترسی و یا تغییر رو هم میتونی راحت پیدا کنی



procedure TForm1.Button1Click(Sender: TObject);
Var SystemTime : _SYSTEMTIME;
CreationTime,LastWriteTime ,LastAccessTime: FileTime;
FS : _OFSTRUCT;
hFile : THandle;
begin
hFile := OpenFile('D:\test.txt',FS,Of_Read);
GetFileTime(hFile, @CreationTime,@LastAccessTime, @LastWriteTime);

FileTimeToSystemTime(CreationTime, SystemTime);
Caption := IntTostr(SystemTime.wYear) + ':' + IntTostr(SystemTime.wMonth) + ':' + IntTostr(SystemTime.wDay);
end;