指定一个文件夹,怎么样设置他的属性。比如只读,隐藏。(100分)

  • 主题发起人 shadow_x
  • 开始时间
S

shadow_x

Unregistered / Unconfirmed
GUEST, unregistred user!
指定一个文件夹,怎么样设置他的属性。比如只读,隐藏。<br>请指教!
 
procedure TFMForm.Properties1Click(Sender: TObject);<br>var<br>&nbsp; Attributes, NewAttributes: Word;<br>begin<br>&nbsp; with FileAttrForm do<br>&nbsp; begin<br>&nbsp; &nbsp; FileDirName.Caption := FileList.Items[FileList.ItemIndex];<br>&nbsp; &nbsp; { set box caption }<br>&nbsp; &nbsp; PathName.Caption := FileList.Directory;<br>&nbsp; &nbsp; { show directory name }<br>&nbsp; &nbsp; ChangeDate.Caption := <br>&nbsp; &nbsp; &nbsp; DateTimeToStr(FileDateToDateTime(FileAge(FileList.FileName)));<br>&nbsp; &nbsp; Attributes := FileGetAttr(FileDirName.Caption);<br>&nbsp; &nbsp; { read file attributes }<br>&nbsp; &nbsp; ReadOnly.Checked := (Attributes and faReadOnly) = faReadOnly;<br>&nbsp; &nbsp; Archive.Checked := (Attributes and faArchive) = faArchive;<br>&nbsp; &nbsp; System.Checked := (Attributes and faSysFile) = faSysFile;<br>&nbsp; &nbsp; Hidden.Checked := (Attributes and faHidden) = faHidden;<br>&nbsp; &nbsp; if ShowModal &lt;&gt; id_Cancel then { execute dialog box }<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; NewAttributes := Attributes;<br>&nbsp; &nbsp; &nbsp; { start with original attributes }<br>&nbsp; &nbsp; &nbsp; if ReadOnly.Checked then<br>&nbsp; &nbsp; &nbsp; &nbsp; NewAttributes := NewAttributes or faReadOnly<br>&nbsp; &nbsp; &nbsp; else <br>&nbsp; &nbsp; &nbsp; &nbsp; NewAttributes := NewAttributes andnot faReadOnly;<br>&nbsp; &nbsp; &nbsp; if Archive.Checked then<br>&nbsp; &nbsp; &nbsp; &nbsp; NewAttributes := NewAttributes or faArchive<br>&nbsp; &nbsp; &nbsp; else <br>&nbsp; &nbsp; &nbsp; &nbsp; NewAttributes := NewAttributes andnot faArchive;<br>&nbsp; &nbsp; &nbsp; if System.Checked then <br>&nbsp; &nbsp; &nbsp; &nbsp; NewAttributes := NewAttributes or faSysFile<br>&nbsp; &nbsp; &nbsp; else <br>&nbsp; &nbsp; &nbsp; &nbsp; NewAttributes := NewAttributes andnot faSysFile;<br>&nbsp; &nbsp; &nbsp; if Hidden.Checked then <br>&nbsp; &nbsp; &nbsp; &nbsp; NewAttributes := NewAttributes or faHidden<br>&nbsp; &nbsp; &nbsp; else <br>&nbsp; &nbsp; &nbsp; &nbsp; NewAttributes := NewAttributes andnot faHidden;<br>&nbsp; &nbsp; &nbsp; if NewAttributes &lt;&gt; Attributes then { if anything changed... }<br>&nbsp; &nbsp; &nbsp; &nbsp; FileSetAttr(FileDirName.Caption, NewAttributes);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ ...write the new values }<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;
 
接受答案了.
 
顶部