delphi - 获得文件属性

文件属性 - Attribute
?

( from delphi help "FindFirst function" )
The Attr parameter specifies the special files to include in addition to all normal files. Choose from these file attribute constants when specifying the Attr parameter:

--------------------------------------------------------------------------------

??? Constant?????? Description????? 数值??? 二进制
??? faReadOnly???? Read-only files?? 1????? 1
??? faHidden?????? Hidden files????? 2????? 10
??? faSysFile????? System files????? 4????? 100
??? faVolumeID???? Volume ID files?? 8????? 1000
??? faDirectory??? Directory files?? 16???? 10000
??? faArchive????? Archive files???? 32???? 100000
??? faAnyFile????? Any file????????? 63???? 111111 (六位)
?
Attributes can be combined by adding (Delphi) or or-ing (C++) their constants or values. For example, to search for read-only and hidden files in addition to normal files, pass (faReadOnly + faHidden) in Delphi or (faReadOnly | faHidden) in C++ as the Attr parameter.
?
Attr 是整型,对应的整数值见上。采用这种形式的整数,从二进制就可以很清楚的看明白。
分别用每一bit位来表示一种属性,faAnyFile对应的就是全1。
?

但是在某些情况下,获得的Attr属性的值并不是上面所说的值。
(XP系统,delphi7,NTFS压缩)
而是如2064(100000 010000,目录),2080(100000 100000,Archive,文件,档案)之类的值。
( 2048 + ? )
可以发现变成了12位。后六位和上表中的意义是一致的。
?

所以,要判断查找到的一个File是什么属性(Attribute),不能直接看其是否等于faArchive等,而是要取出后面的六位,然后再判断。
?
?

--------------------------------------------------------------------------------

?
现象:
?
下面是一些例子
?
?? C盘(XP, NTFS,未压缩)下,
.?????????????????? 16
..????????????????? 16
一般目录??????????? 16
一般的文件????????? 32
目录MATLAB6p5?????? 48 = 32 + 16 ??
目录Program Files?? 17 = 16 + 1
文件AUTOEXEC.BAT??? 2
文件arcsetup.exe??? 39 = 1 + 2 + 4 +32
文件boot.ini??????? 38 = 32 + 2 + 4
文件iprpzi.hxo????? 34 = 32 + 2
目录MSOCache??????? 19 = 1 + 2 + 16
目录System Volume Information 8214 = 16 + 2 + 4 + 100000 00010110 B
?????????????????????????????????? = 16 + 2 + 4 + 8192(2048*4)
?
?? D盘(NTFS,压缩)下
目录?????????????????? 2064 = 2048 + 16
文件?????????????????? 2080 = 2048 + 32
目录Recycler?????????? 2070 = 2048 + 22 = 2048 + 2 + 4 + 16
目录System Volume Information???????? 22 = 2 + 4 + 16
文件Thumbs.db????????? 2086 = 2 + 4 + 32 + 2048
文件TREEINFO.WC??????? 2050 = 2048 + 2
?

?? H盘(Win2000,NTFS,未压缩)
目录Program Files???????? 49 = 1 + 16 + 32
目录WINNT???????????????? 48 = 16 + 32
?

--------------------------------------------------------------------------------

?

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值