作者bleeza (what's wrong with ptt?)
看板Visual_Basic
标题[.NET] FileSystemInfo的属性attributes
时间Wed Dec 19 11:33:01 2007
Dim i As Integer
Dim fileAttr() As Integer = {FileAttributes.Archive, _
FileAttributes.Compressed, FileAttributes.Device, _
FileAttributes.Directory, FileAttributes.Encrypted, _
FileAttributes.Hidden, FileAttributes.Normal, _
FileAttributes.NotContentIndexed, FileAttributes.Offline, _
FileAttributes.ReadOnly, FileAttributes.ReparsePoint, _
FileAttributes.SparseFile, FileAttributes.System, _
FileAttributes.Temporary}
Dim fileAttrString() As String = {"Archive", "Compressed", _
"Device", "Directory", "Encrypted", "Hidden", "Normal", _
"NotContentIndexed", "Offline", "ReadOnly", "ReparsePoint", _
"SparseFile", "System", "Temporary"}
Dim attr As String
Dim di As DirectoryInfo = New DirectoryInfo("C:\123")
Try
Dim dirs As DirectoryInfo() = di.GetDirectories("*")
Dim info As DirectoryInfo
For Each info In dirs
Response.Write("目录 : " & info.Name & " --- ")
attr = ""
For i = fileAttr.GetLowerBound(0) To fileAttr.GetUpperBound(0)
if (
info.Attributes And fileAttr(i)) <> 0 Then
If attr <> "" Then
attr += ", "
End If
attr += fileAttrString(i)
End If
Next i
Response.Write("属性 : " & attr & "<br />")
Next info
Catch e As Exception
Response.Write("有错误发生 : " & e.ToString())
End Try
====================================
黄色部份想请教各位高手
程式执行会SHOW出内容如下
目录 : aaa --- 属性 : Directory, Hidden
目录 : bbb --- 属性 : Directory
目录 : ccc --- 属性 : Archive, Directory
--------------------------------------------
请问一下要怎麽解释if (info.Attributes And fileAttr(i)) <> 0这个判断式?
另外,这是不是表示VB的判断式可以用0 1 来表示true or false
不像JAVA的boolean值只能用true false来表示
谢谢罗!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 163.30.45.196
※ 编辑: bleeza 来自: 163.30.45.196 (12/19 11:33)
※ 编辑: bleeza 来自: 163.30.45.196 (12/19 11:38)
1F:→ jujudy:And 用在数值时属於「位元运算」, 而非「逻辑运算」 12/19 11:55