获取文件属性中详细信息里的各项目(vb 学习备注)

Sub ts()

    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)
                    Debug.Print s
                    
                End If
                
            Next i
            
            MsgBox s, vbInformation, "文件属性"
            
        End If
        
    End With
    
    Set oDLG = Nothing
    
End Sub

先引用Microsoft Shell Controls and Automation



VBA实例

Sub ts()

    Dim pth As String
    Dim Flname As String
    Dim sPath As String
    Dim sOwner As String
    
    Dim shl As Shell32.Shell
    Dim shfd As Shell32.Folder
    Dim s As String
    Dim i As Integer
    
    sPath = "\\10.116.0.26\smc82files\06、公用文件\"
    Flname = Dir(sPath)
    
    i = 2
    
    Do While Flname <> ""
    
        If Flname <> "." And Flname <> ".." Then
    
            If GetAttr(sPath & Flname) = vbDirectory Then
            
                Flname = Dir()
                
            Else
            
                Set shl = New Shell
                Set shfd = shl.Namespace(sPath)
                ActiveSheet.Cells(i, 1).Value = Flname
                ActiveSheet.Cells(i, 2).Value = shfd.GetDetailsOf(shfd.Items.Item(Flname), 10)
                ActiveSheet.Cells(i, 3).Value = shfd.GetDetailsOf(shfd.Items.Item(Flname), 20)
                i = i + 1
                Flname = Dir()
                
            End If
            
        Else
        
            Flname = Dir()
            
        End If
            
    Loop
    
    MsgBox "ok"
                
End Sub


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值