求教!!如何修改某文件的生成、修改、访问等时间参数??
解决方案 »
- 用过fastscript的请进,高分相送,up也有分!
- 在线给分........................................................点击dbgrid中的一条记录后,为什么dbgrid.selectedrows.cout的值为零
- 这个数据库这样这样定义好不好?高手请进,热烈拥抱!!!!!!!!!!
- 郁闷+强烈抗议!
- 简单问题,捡分啊
- 急!大家来帮一下忙。谢谢啊!! 很简单的一个问题,高分求救!
- 然后让线程在指定的时间内如果还没有结束就自动停止?
- 帮帮忙!!100分够不够??
- ********大送分了(谁知道<<delphi 5企业级解决方案及应用剖析>>的范例代码哪里下载?
- 如何实现可录入并有自动检索功能的下拉列表
- 如何创建复制一个窗体??
- 请问各位大虾,还有和csdn相类式的可以讨论Delphi开发的论坛吗?
{these record structures allow for easy manipulation of Dos
date and time values}
TDosTime=Record
Hour : Byte;
Minutes : Byte;
seconds : Byte;
end; TDosDate = Record
Year : Word;
Month : Byte;
Day : Byte;
end;var
Form1: TForm1;
hFile: THandle; // a handle to the opened fileimplementation{this function provides a convenient way to convert a Dos time into its component parts}
function ConvertDosTimeToSystemTime(FileDosTime: WORD): TDosTime;
var
DosTime: TDosTime;
begin
DosTime.Seconds := (FileDosTime and $1F) * 2;
DosTime.Minutes := (FileDosTime and $7E0) shr 5;
DosTime.Hour := (FileDosTime and $F800) shr 11;
Result := DosTime;
end;{this function provides a convenient way to convert a
Dos date into its component parts}function ConvertDosDateToSystemDate(FileDosDate: WORD): TDosDate;
var
DosDate: TDosDate;
begin
DosDate.Day := FileDosDate and $1F;
DosDate.Month := FileDosDate and $1E0 shr 5;
DosDate.Year := (FileDosDate and $FE00) shr 9 + 1980;
Result := DosDate;
end;procedure TForm1.SpeedButton2Click(Sender: TObject);
var
Security: TSecurityAttributes; // attributes for the opened file FileName: PChar; // holds the filename
WriteTime, LocalTime: TFILETIME; // holds file times
DosDate, DosTime: WORD; // holds the Dos date and time
infoDosTime: TDosTime; // holds Dos time information
infoDosDate: TDosDate; // holds Dos date information
SystemTime: TSystemTime; // holds the last modification timebegin
{setup the security attributes for the opened file}
Security.nLength := SizeOf(TSecurityAttributes);
Security.lpSecurityDescriptor := nil;
Security.bInheritHandle := FALSE; {display the open dialog box}
if OpenDialog1.Execute then
begin
{display the selected filename...}
FileName := PChar(OpenDialog1.FileName);
StatusBar1.SimpleText := FileName; {...and open it} hFile := CreateFile(PChar(FileName),GENERIC_READ or GENERIC_WRITE,
FILE_SHARE_READ or FILE_SHARE_WRITE, @Security,
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); {if there was an error, show a message}
if hFile = INVALID_HANDLE_VALUE then
begin
ShowMessage('Error Opening File');
Exit;
end;
end; {retrieve the last modification time} GetFileTime(hFile, nil, nil, @WriteTime); {convert the time to local file time}
FileTimeToLocalFileTime(WriteTime, LocalTime); {finally, convert the time to the system time, so that it
will match the file time displayed in the Explorer}
FileTimeToSystemTime(LocalTime, SystemTime); {convert the file time into Dos date and time components...}
FileTimeToDosDateTime(LocalTime, DosDate, DosTime); {...and convert it back} if not DosDateTimeToFileTime(DosDate, DosTime, LocalTime) then
ShowMessage ('An error occured when converting Dos date and time back to'+
' file time.'); {break out the component parts of the Dos date and time for easy display}
infoDosTime := ConvertDosTimeToSystemTime(DosTime);
infoDosDate := ConvertDosDateToSystemDate(DosDate); with infoDosTime do
Edit1.Text := ComboBox1.Items[infoDosDate.Month - 1]+ ' ' + IntToStr(infoDosDate.Day) + ',' +
IntToStr(infoDosDate.Year) + ' ' +
IntToStr(Hour) + ':' +
IntToStr(Minutes) + ':' +
IntToStr(Seconds) ; {indicate the time of day}
case SystemTime.WHour of
12 : Label1.Caption := 'PM';
13..24 : begin
Label1.Caption := 'PM';
SystemTime.wHour:=SystemTime.wHour - 12; end;
0 : SystemTime.wHour:= 12;
else
Label1.Caption := 'AM';
end; {display the last modification time of the file}
SpinEdit1.Value := SystemTime.wYear;
SpinEdit2.Value := SystemTime.wHour;
SpinEdit3.Value := SystemTime.wMinute;
SpinEdit4.Value := SystemTime.wSecond;
ComboBox1.ItemIndex := SystemTime.wMonth - 1;
Calendar1.Month := SystemTime.wMonth;
Calendar1.Day := SystemTime.wDay;end;procedure TForm1.SpeedButton3Click(Sender: TObject);
var
FileTime, LocalFileTime: TFileTime; // holds file times
SystemTime: TSystemTime; // holds system time information
begin
{prepare the time information from the values set by the user}
SystemTime.wHour := SpinEdit2.Value; if (Label1.Caption = 'PM') and (SystemTime.wHour < 12) then
SystemTime.wHour := SystemTime.wHour + 12; SystemTime.wMinute := SpinEdit3.Value;
SystemTime.wSecond := SpinEdit4.Value;
SystemTime.wYear := SpinEdit1.Value;
SystemTime.wMonth := ComboBox1.ItemIndex + 1;
SystemTime.wDay := Calendar1.Day; {convert the system time to a local file time}
SystemTimeToFileTime(SystemTime,LocalFileTime); {convert the local file time to a file time that the file system understands}
LocalFileTimeToFileTime(LocalFileTime,FileTime); {use this time to set the last modification time which shows
up in the Explorer}
SetFileTime(hFile, nil, nil, @FileTime);
end;
//文件属性;SetFileAttributes;
var
FileAttributes: DWORD; // holds collective file attributes
begin
FileAttributes := 0; if CheckBox1.Checked then
FileAttributes := FileAttributes or FILE_ATTRIBUTE_ARCHIVE;
if CheckBox2.Checked then
FileAttributes := FileAttributes or FILE_ATTRIBUTE_DIRECTORY;
if CheckBox3.Checked then
...
{set the file attributes of the selected file}
if not SetFileAttributes(PChar(FileListBox1.FileName), FileAttributes) then
...
//getFileattributes:
CheckBox1.Checked := Boolean(GetFileAttributes(PChar(FileListBox1.FileName))
and FILE_ATTRIBUTE_ARCHIVE);