在ASP中如何将代码生成的文件设为只读

发表于:2007-06-30来源:作者:点击数: 标签:
Attributes Propertybr Sets or returns the attributes of files or folders. Read/write or read-only, depending on the attribute.br br object.Attributes [= newattributes] br br Argumentsbr objectbr br Required. Always the name of a File or Fol
Attributes Property<br>
Sets or returns the attributes of files or folders. Read/write or read-only, depending on the attribute.<br>
<br>
object.Attributes [= newattributes] <br>
<br>
Arguments<br>
object<br>
<br>
Required. Always the name of a File or Folder object.<br>
<br>
newattributes<br>
<br>
Optional. If provided, newattributes is the new value for the attributes of the specified object.<br>
<br>
Settings<br>
The newattributes argument can have any of the following values or any logical combination of the following values:<br>
<br>
Constant Value Description <br>
Normal 0 Normal file. No attributes are set. <br>
ReadOnly 1 Read-only file. Attribute is read/write. <br>
Hidden 2 Hidden file. Attribute is read/write. <br>
System 4 System file. Attribute is read/write. <br>
Directory 16 Folder or directory. Attribute is read-only. <br>
Archive 32 File has changed since last backup. Attribute is read/write. <br>
Alias 1024 Link or shortcut. Attribute is read-only. <br>
Compressed 2048 Compressed file. Attribute is read-only. <br>
<br>
<br>
Remarks<br>
Attempts to change any of the read-only attributes (Alias, Compressed, or Directory) are ignored. <br>
<br>
When setting attributes, it is generally a good idea to first read the current attributes, then change the individual attributes as desired, and finally write the attributes back.<br>
<br>
The following code illustrates the use of the Attributes property with a file: <br>
<br>
Function ToggleArchiveBit(filespec)<br>
&nbsp;&nbsp;&nbsp;Dim fso, f<br>
&nbsp;&nbsp;&nbsp;Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)<br>
&nbsp;&nbsp;&nbsp;Set f = fso.GetFile(filespec)<br>
&nbsp;&nbsp;&nbsp;If f.attributes and 32 Then<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f.attributes = f.attributes - 32<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ToggleArchiveBit = &quot;Archive bit is cleared.&quot;<br>
&nbsp;&nbsp;&nbsp;Else<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f.attributes = f.attributes + 32<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ToggleArchiveBit = &quot;Archive bit is set.&quot;<br>
&nbsp;&nbsp;&nbsp;End If<br>
End Function<br>

原文转自:http://www.ltesting.net