怎么修改文件夹的只读属性?急!!! ( 积分: 50 )

  • 主题发起人 主题发起人 pl5th2001
  • 开始时间 开始时间
P

pl5th2001

Unregistered / Unconfirmed
GUEST, unregistred user!
想把文件夹内的所有文件的只读属性去掉,怎么写?大家快忙我想想办法
 
想把文件夹内的所有文件的只读属性去掉,怎么写?大家快忙我想想办法
 
procedure TForm1.Button1Click(Sender: TObject);<br>var<br> &nbsp;Attributes: Word;<br>begin<br> &nbsp;Attributes:= FileGetAttr('c:/test');<br> &nbsp;if Attributes and faReadOnly &lt;&gt;0 then<br> &nbsp; &nbsp;FileSetAttr('c:/test', Attributes - faReadOnly);<br>end;
 
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 and not 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 and not 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 and not 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 and not 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; { ...write the new values }<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br>end;
 
多人接受答案了。
 

Similar threads

回复
0
查看
812
不得闲
回复
0
查看
1K
不得闲
D
回复
0
查看
778
DelphiTeacher的专栏
D
D
回复
0
查看
818
DelphiTeacher的专栏
D
后退
顶部