var rc:TSearchRec;用findfirst('c:\ling\*.*',faAnyFile,rc); 我知道此目录下肯定有文件存在。 为什么rc.name的返回值是'.'?
这是因为DOS有两个 1. . 2. ..
1.if rc.name <> '.' or rc.name <> '..' then 2. procedure TFMForm.Properties1Click(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;
用它的Items属性能得到所有文件名
用DELETEFILE?
rc:TSearchRec;用findfirst('c:\ling\*.*',faAnyFile,rc);
我知道此目录下肯定有文件存在。
为什么rc.name的返回值是'.'?
1. .
2. ..
2.
procedure TFMForm.Properties1Click(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;