![深入解析ASP核心技术](https://wfqqreader-1252317822.image.myqcloud.com/cover/373/837373/b_837373.jpg)
上QQ阅读APP看书,第一时间看更新
1.5.1 文件夹属性
Folder对象的属性如表1-5所示。
表1-5 Folder对象的属性
![](https://epubservercos.yuewen.com/54F32D/5128954204275601/epubprivate/OEBPS/Images/figure_0021_0002.jpg?sign=1738883299-vwXu7PfxDakTWQPFdYO087FhDmWq8UwT-0-f1aa815ca631a4036180648d450fbbc0)
下例将输出C:\Program Files\Common Files\这个文件夹的各种属性。
Folder.asp
<%@codepage=936%> <% Response.Charset = "GBK" folderPath = "C:\Program Files\Common Files\" Set fso = CreateObject("Scripting.FileSystemObject") '判断文件夹是否存在 If fso.FolderExists(folderPath) Then Set folder = fso.GetFolder(folderPath) '取得Folder对象 '输出各种属性 Response.Write "属性:" & folder.Attributes &"<br>" Response.Write "创建时间:" & folder.DateCreated &"<br>" Response.Write "上次访问时间:" & folder.DateLastAccessed & "<br>" Response.Write "上次修改时间:" & folder.DateLastModified & "<br>" Response.Write "所在驱动器:" & folder.Drive &"<br>" Response.Write "根目录:" & folder.IsRootFolder &"<br>" Response.Write "文件夹名:" & folder.Name &"<br>" Response.Write "父文件夹:" & folder.ParentFolder &"<br>" Response.Write "路径:" & folder.Path &"<br>" Response.Write "短文件夹名:" & folder.ShortName &"<br>" Response.Write "短路径:" & folder.ShortPath &"<br>" Response.Write "大小:" & folder.Size &"字节<br>" Response.Write "类型:" & folder.Type & "<br>" Else Response.Write "文件夹不存在。" End If Set fso = Nothing %>
运行结果如图1-4所示。
![](https://epubservercos.yuewen.com/54F32D/5128954204275601/epubprivate/OEBPS/Images/figure_0022_0001.jpg?sign=1738883299-UEJmvc70QOs1EnsPOlg9ZzWVSn4c7uiO-0-49b3b113debcfc0c196d3a0ee9df934d)
图1-4 输出文件夹的属性
Attributes属性的可选值如表1-6所示。
表1-6 Attributes属性的可选值
![](https://epubservercos.yuewen.com/54F32D/5128954204275601/epubprivate/OEBPS/Images/figure_0022_0002.jpg?sign=1738883299-2XN9TmScsHc6752n6ug1kDD4YKbVQF8N-0-5aca661950064fc2489bf511eab7b8c2)
实际上,这个列表是文件夹和文件共用的。
一个对象的Attributes属性可以是列表中值的组合。如只读文件夹是17(1+16),系统文件夹是20(4+16),只读隐藏系统文件夹是23(1+2+4+16),以此类推。
判断或去除某个Attributes属性时,建议使用逻辑运算符。如判断对象是否是隐藏的,可以使用AND运算符进行判断。
If folder.Attributes AND 2 Then Response.Write "是隐藏的" End If
如果想将对象变为不隐藏,可以使用XOR运算符。
folder.Attributes = folder.Attributes XOR 2
表1-6中的读写是什么意思呢?以Attributes值为16为例,如果一个对象的值是16 (也可能是17、18、19等),那么表示它是一个文件夹,这个事实是不允许更改的,所以这个值是只读的。换句话说,16这个值始终是与文件夹绑定的,不能去掉它,一个文件夹的Attributes属性一定大于等于16。