同上
解决方案 »
- 大家好,我是风筝!本人将陆续推出delphi7在线帮助的翻译,请大家支持
- 如何绑定ODBC数据库,谁给我一断代码
- 关于ComboBox的问题
- 每增加一个ADODataSet与DataSource,Exe的大小会增加多少?
- %%%%%%找呀找呀帮人找工作,上海和杭州的朋友请注意一下(关乎生计请版主留情)(老鱼)
- Delphi6中是否仍可以使用链表?如果可以如何定义??
- 急急,在线等待,delphi6注册码
- 记录指针和记录变量区别??
- WaveInPrepareHeader函数什么情况下报MMSYSERR_NOMEM错误,
- 如何编写WindowsNT服务程序?
- 怎样保存IDE的设置?
- 有没有更改窗体样子的控件
var
sr: TSearchRec;
ss: TStrings;
dirName: string;
begin
dirName := 'c:\';
ss := TStringList.Create;
if FindFirst(dirName + '*.*', faDirectory, sr) = 0 then begin
repeat
if (sr.Attr and faDirectory) = sr.Attr then
ss.Add(sr.Name);
until FindNext(sr) <> 0;
FindClose(sr);
end;
ShowMessage(IntToStr(ss.Count));
ss.Free;
end;
再请问 sysu(死树) (sr.Attr and faDirectory) = sr.Attr 这句怎么理解???
sr.Attr and faDirectory
Integer $00000010 怎么来看呢?
// getFileListFromDir('c:\windows',false,fileList);
//c:\windows or c: ture|false
procedure getFileListFromDir(dir:string;includeSubDir:boolean;var fileList:TStringList);
var
sr:TSearchRec;
path:String;
begin
path:=dir+'\'; //c:\windows\
dir:=dir+'\*.*'; //c:\windows\*.*
if findFirst(dir,faanyfile,sr)=0 then
repeat
begin
if (sr.Name<>'.') and (sr.Name<>'..') and ((fileGetAttr(path+sr.Name) and faDirectory)<>faDirectory) then
fileList.Add(path+sr.Name);
if (includeSubDir) and (sr.Name<>'.') and (sr.Name<>'..') and ((fileGetAttr(path+sr.Name) and faDirectory)=faDirectory) then
getFileListFromDir(path+sr.Name,includeSubDir,fileList);
end;
until findNext(sr)<>0;
findClose(sr);
end;
如果sr.Attr = faArchive // $00000020
则(sr.Attr and faDirecotry) = 0,所以取到的不是faDirectory,
如果sr.Attr = faDirectory // $00000010
则(sr.Attr and faDirecotry) = $00000010,所以取得的是faDirectory,
............
if (sr.Attr and faDirectory) = sr.Attr then
...........
死树兄的这行代码判断出来的应该是非只读的文件夹,如果只是列出忽略只读属性的话,应改为:
if (sr.Attr and (faDirectory + faReadOnly) ) = sr.Attr then
1 AND x = x
1 OR x = 1
0 AND x = 0
0 OR x = x
一个文件有可能有几种属性,例如 faHidden = $00000002,faDirectory = $00000010,那么一个隐藏文件夹的属性就是 faHidden + faDirectory,也就是 $12 sr.Attr,这样使用 $12 AND faHidden(00010010 AND 00000010 = 00000010),就可以测试出是否包含了隐藏属性。
1 AND x = x
1 OR x = 1
0 AND x = 0
0 OR x = x的说
)