vb如何获取文件属性等信息

2024-11-27 20:21:18
推荐回答(4个)
回答1:

'工程-引用 “Microsoft Shell Controls And Automation”

Private Sub Command1_Click()
Dim oDLG
Dim pth As String
Dim Flname As String

Dim shl As Shell32.Shell
Dim shfd As Shell32.Folder
Dim s As String
Dim i As Integer
Set oDLG = CreateObject("MSComDlg.CommonDialog")
With oDLG
.DialogTitle = "打开文件"
.Filter = "所有文件|*.*"
.MaxFileSize = 255
.ShowOpen
If .FileName <> "" Then
i = InStrRev(.FileName, "\")
If i = 0 Then Exit Sub
Flname = Mid(.FileName, i + 1)
Set shl = New Shell
Set shfd = shl.NameSpace(Left(.FileName, i - 1))

For i = 0 To 39
If shfd.GetDetailsOf(0, i) <> "" And shfd.GetDetailsOf(shfd.Items.Item(Flname), i) <> "" Then
s = s & i & ":" & shfd.GetDetailsOf(0, i) & ": " & shfd.GetDetailsOf(shfd.Items.Item(Flname), i) & Chr(10)
End If
Next i
MsgBox s, vbInformation, "文件属性"
End If
End With
Set oDLG = Nothing
End Sub

回答2:

使用VB的GetAttr函数可以获取文件属性吵州
它返回一个整数代表已存在文件的属性

用法
l=getattr(<你的文件>)
If l And vbDirectory Then '这个是个文件掘坦夹
If l And vbHidden Then '隐藏文件
If l And vbReadOnly Then '只升散蔽读文件
If l And vbSystem Then '系统文件

回答3:

http://hi.baidu.com/cfan_/blog/item/9c024bddf8673de976c638d0.html

参芦敏考下这个文章吧

我原来有获取衫缓详或哗模细信息的代码的 ,只是找不到了呵呵 - -|,我只找到了类似于这个的。

回答4:

FileSystemObject