送你一个例子吧:
procedure TForm1.Button1Click(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;
procedure TForm1.Button1Click(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;
解决方案 »
- Delphi重新编译后EXE文件变大
- 求高手指点,Web服务器与应用服务器程序的交互
- 有没有可以偷懒的方法啊??
- 各位用StretchDraw缩放图象,和直接把TImage的属性Stretch设为True有什么区别?
- 关于insert 语句 参数问题
- 急,这是什么问题啊?
- 如果我想把Express QuantumGrid中的指定行号的行,标颜色怎么办啊?可加分
- 在程序运行时如何实现拖动、调整控件的大小,
- StringGrid双击列分隔线调整列宽为最适合列宽
- Delphi 如何以字节数组的形式以套接字发送数据?
- 如何修改button上的文字颜色,我为什么屡试不行?(在线等候)
- 不得不再问这个关于treeview的问题,问了好久了,难道没有高手?
The GetFileAttributes function returns attributes for a specified file or directory. DWORD GetFileAttributes( LPCTSTR lpFileName // address of the name of a file or directory
);
ParameterslpFileNamePoints to a null-terminated string that specifies the name of a file or directory. Windows NT:There is a default string size limit for paths of MAX_PATH characters. This limit is related to how the GetFileAttributes function parses paths. An application can transcend this limit and send in paths longer than MAX_PATH characters by calling the wide (W) version of GetFileAttributes and prepending "\\?\" to the path. The "
\\?\" tells the function to turn off path parsing; it lets paths longer than MAX_PATH be used with GetFileAttributesW. This also works with UNC names. The "\\?\" is ignored as part of the path. For example, "
\\?\C:\myworld\private" is seen as "C:\myworld\private", and "\\?\UNC\bill_g_1\hotstuff\coolapps" is seen as "\\
bill_g_1\hotstuff\coolapps".Windows 95:The lpFileName string must not exceed MAX_PATH characters. Windows 95 does not support the "\\?\" prefix. Return ValuesIf the function succeeds, the return value contains the attributes of the specified file or directory.
If the function fails, the return value is 0xFFFFFFFF. To get extended error information, call GetLastError.
The attributes can be one or more of the following values:
是不是这样?
thanks!
等一下再加分!
if fileexists(StrName) then
showmessage('是文件');