文件属性值的运算
- Delphi(Pascal) code
procedure TForm1.Button1Click(Sender: TObject);var FileRec:TSearchrec; s:String;begin s:='E:\FWGL\data.mdb'; findfirst(S,faAnyfile,FileRec); ShowMessage(S+'的属性值为:'+inttostr(FileRec.Attr)); //显示32 ShowMessage('常量 aDirectory 的值为:'+inttostr(faDirectory)); //16 if ((FileRec.Attr and faDirectory) = 0) then ShowMessage('按位与值:'+inttostr(FileRec.Attr and faDirectory)+' '+S+' 是一个文件.') else showMessage('按位与值:'+inttostr(FileRec.Attr and faDirectory)+' '+s+' 是一个文件夹');end;这里的 FileRec.Attr 的值为何是 32? 如果加了个只读,那就是33
为何 32 and 16 = 0 就能判断其是否是一个文件而不是文件夹?
它们之前有什么关系? 怎么运算的?
[解决办法]
[解决办法]
LZ先要解决,与运算(即and)是什么?是怎么样进行运算的?
可以看帮助或者看源码知道各个属性值是多少,注意他们每个值都是不同的
然后把它转换成2进制,2个数进行与运算,结果就出来了
比如faDirectory用2进制表示是0001 0000
任何一个数和它进行and运算,只有第4位为1时,结果才会不等于0
而所有这些属性值当中只有他自己是
所以...