积极答复者
VB2008怎么才能获得文件属性的字符串?

问题
-
我的代码是:
Public Function F_GetFileInfo(ByVal gfiName As String) As System.IO.FileInfo '得到文件的信息
On Error Resume Next
F_GetFileInfo = Microsoft.VisualBasic.FileIO.FileSystem.GetFileInfo(gfiName)
WriteError()
'waitInput()
End FunctionPublic Function F_GetFileAttirb(ByVal gfaFile As String) As String '得到文件属性
Dim tmpstr3 As String, fInfo As System.IO.FileInfo
fInfo = F_GetFileInfo(gfaFile)
tmpstr3 = ""
If fInfo.Attributes = IO.FileAttributes.Archive Then
tmpstr3 = tmpstr3 + "Archive/"
ElseIf fInfo.Attributes = IO.FileAttributes.Compressed Then
tmpstr3 = tmpstr3 + "Compressed/"
ElseIf fInfo.Attributes = IO.FileAttributes.Device Then
tmpstr3 = tmpstr3 + "Device/"
ElseIf fInfo.Attributes = IO.FileAttributes.Directory Then
tmpstr3 = tmpstr3 + "Directory/"
ElseIf fInfo.Attributes = IO.FileAttributes.Encrypted Then
tmpstr3 = tmpstr3 + "Encrypted/"
ElseIf fInfo.Attributes = IO.FileAttributes.Hidden Then
tmpstr3 = tmpstr3 + "Hidden/"
ElseIf fInfo.Attributes = IO.FileAttributes.Normal Then
tmpstr3 = tmpstr3 + "Normal/"
ElseIf fInfo.Attributes = IO.FileAttributes.NotContentIndexed Then
tmpstr3 = tmpstr3 + "NCI/"
ElseIf fInfo.Attributes = IO.FileAttributes.Offline Then
tmpstr3 = tmpstr3 + "Offline/"
ElseIf fInfo.Attributes = IO.FileAttributes.ReadOnly Then
tmpstr3 = tmpstr3 + "ReadOnly/"
ElseIf fInfo.Attributes = IO.FileAttributes.ReparsePoint Then
tmpstr3 = tmpstr3 + "ReparsePoint/"
ElseIf fInfo.Attributes = IO.FileAttributes.SparseFile Then
tmpstr3 = tmpstr3 + "Sparse/"
ElseIf fInfo.Attributes = IO.FileAttributes.System Then
tmpstr3 = tmpstr3 + "System/"
ElseIf fInfo.Attributes = IO.FileAttributes.Temporary Then
tmpstr3 = tmpstr3 + "Temporary/"
End If
F_GetFileAttirb = tmpstr3
End Function可是除了文件属性是"Archive会的到输出,其它的都没用啊
答案
-
因为你用ElseIf ,第一个条件满足,其他都不走了
改成这样
If fInfo.Attributes = IO.FileAttributes.Archive Then
tmpstr3 = tmpstr3 + "Archive/"
end ifIf fInfo.Attributes = IO.FileAttributes.Compressed Then
tmpstr3 = tmpstr3 + "Compressed/"end if
http://feiyun0112.cnblogs.com/- 已建议为答案 l915817 2010年7月21日 5:04
- 已标记为答案 Min-Hong Tang - MSFT 2010年8月9日 11:01
全部回复
-
因为你用ElseIf ,第一个条件满足,其他都不走了
改成这样
If fInfo.Attributes = IO.FileAttributes.Archive Then
tmpstr3 = tmpstr3 + "Archive/"
end ifIf fInfo.Attributes = IO.FileAttributes.Compressed Then
tmpstr3 = tmpstr3 + "Compressed/"end if
http://feiyun0112.cnblogs.com/- 已建议为答案 l915817 2010年7月21日 5:04
- 已标记为答案 Min-Hong Tang - MSFT 2010年8月9日 11:01
-
你修改一个文件的只读属性可以看到效果
If fInfo.Attributes And IO.FileAttributes.Archive = IO.FileAttributes.Archive Then
tmpstr3 = tmpstr3 + "Archive/"
End IfIf fInfo.Attributes And IO.FileAttributes.ReadOnly = IO.FileAttributes.ReadOnly Then
tmpstr3 = tmpstr3 + "ReadOnly/"
End If
http://feiyun0112.cnblogs.com/