如何取得文件夹的属性以及某文件的属性?

ahpei 2002-05-22 03:06:55
就是指在文件夹上点鼠标右键出现的那个属性!!以及文件的属性!
用DELPHI!!!请给代码!谢谢!
...全文
69 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
lizhenjia 2002-05-22
  • 打赏
  • 举报
回复
判断是文件还是文件夹:
if fileexists(StrName) then
showmessage('是文件');

ahpei 2002-05-22
  • 打赏
  • 举报
回复
怎么加分?
ahpei 2002-05-22
  • 打赏
  • 举报
回复
那怎么判断如 'C:\Windows\Log' 这个Log到底是文件夹还是文件?如果刚好有一个LOG的文件夹跟一个log.txt的文件呢?要怎么办?
thanks!
等一下再加分!
ahpei 2002-05-22
  • 打赏
  • 举报
回复
模仿?根据WINDOWS出现的那个窗口自己写代码找比如文件大小,创建时间等??
是不是这样?
lizhenjia 2002-05-22
  • 打赏
  • 举报
回复
FileGetAttr/FileSetAttr
MFC2001 2002-05-22
  • 打赏
  • 举报
回复
API
The GetFileAttributes function returns attributes for a specified file or directory.

DWORD GetFileAttributes(

LPCTSTR lpFileName // address of the name of a file or directory
);


Parameters

lpFileName

Points 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 Values

If 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:
lizhenjia 2002-05-22
  • 打赏
  • 举报
回复
送你一个例子吧:
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;
chinaway 2002-05-22
  • 打赏
  • 举报
回复
gz,有难度

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧