要获取所有文件的列表,请在本地计算机中键入 [英] To get list of all files type in local computer

查看:69
本文介绍了要获取所有文件的列表,请在本地计算机中键入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取本地计算机中所有文件类型的列表????

How to get list of all files type in local computer?????

推荐答案

' make a reference to a directory
    Dim di As New IO.DirectoryInfo("c:\")
    Dim diar1 As IO.FileInfo() = di.GetFiles()
    Dim dra As IO.FileInfo

   'list the names of all files in the specified directory
    For Each dra In diar1
        ListBox1.Items.Add(dra)
    Next


Private Const MAX_PATH As Long = 260
Private Const HKEY_CLASSES_ROOT As Long = &H80000000
Private Const ERROR_SUCCESS As Long = 0
Private Const vbDot As Long = 46 ' Asc(".") = 46
Private Const SHGFI_USEFILEATTRIBUTES As Long = &H10
Private Const SHGFI_TYPENAME As Long = &H400
Private Const LB_SETTABSTOPS As Long = &H192

Private Type FILETIME
   dwLowDateTime As Long
   dwHighDateTime As Long
End Type

Private Type SHFILEINFO 
   hIcon As Long
   iIcon As Long
   dwAttributes As Long
   szDisplayName As String * MAX_PATH
   szTypeName As String * 80
End Type

Private Declare Function RegEnumKeyEx Lib "advapi32" _
   Alias "RegEnumKeyExA" _
   (ByVal hKey As Long, _
   ByVal dwIndex As Long, _
   ByVal lpName As String, _
   lpcbName As Long, _
   ByVal lpReserved As Long, _
   ByVal lpClass As String, _
   lpcbClass As Long, _
   lpftLastWriteTime As FILETIME) As Long

Private Declare Function SHGetFileInfo Lib "shell32" _
   Alias "SHGetFileInfoA" _
  (ByVal pszPath As String, _
   ByVal dwFileAttributes As Long, _
   psfi As SHFILEINFO, _
   ByVal cbFileInfo As Long, _
   ByVal uFlags As Long) As Long

Private Declare Function SendMessage Lib "user32" _
   Alias "SendMessageA" _
  (ByVal hwnd As Long, _
   ByVal wMsg As Long, _
   ByVal wParam As Long, _
   lParam As Any) As Long


Private Sub Form_Load()

  'Setup tabstops in the listbox by first
  'clearing existing tabs, then setting the
  'new tabstop value.
  
   ReDim TabArray(0) As Long
   
  'only one tabstop
   TabArray(0) = 75
  
   Call SendMessage(List1.hwnd, LB_SETTABSTOPS, 0&, ByVal 0&)
   Call SendMessage(List1.hwnd, LB_SETTABSTOPS, 1&, TabArray(0))
   List1.Refresh
   
   Command1.Caption = "Get Associations"

End Sub


Private Sub Command1_Click()

   List1.Clear
   Me.MousePointer = 11
   
  'fill the listbox box with the
  'file types and their extensions
   Call GetAssociatedFileListing
   
   Me.MousePointer = 0
   
End Sub


Private Sub GetAssociatedFileListing()

   Dim dwIndex As Long
   Dim sTypeName As String
   Dim sSubkey As String * MAX_PATH
   Dim sClass As String * MAX_PATH
   Dim ft As FILETIME
   
   Do While RegEnumKeyEx(HKEY_CLASSES_ROOT, _
                         dwIndex, _
                         sSubkey, _
                         MAX_PATH, _
                         0, sClass, _
                         MAX_PATH, ft) = ERROR_SUCCESS
      
      If Asc(sSubkey) = vbDot Then
         
        'Pass the returned string to get the file type
         sTypeName = GetFileType(sSubkey)
            
         If Len(sTypeName) > 0 Then
            List1.AddItem TrimNull(sSubkey) & vbTab & sTypeName
         End If
            
      End If

      dwIndex = dwIndex + 1
   
   Loop

End Sub


Private Function GetFileType(sFile As String) As String

  'If successful returns the specified file's
  'typename, returns an empty string otherwise.
  'sFile does not have to exist and can be
  'just a file extension.
   Dim sfi As SHFILEINFO

   If SHGetFileInfo(sFile, 0&, _
                    sfi, Len(sfi), _
                    SHGFI_TYPENAME Or SHGFI_USEFILEATTRIBUTES) Then
      GetFileType = TrimNull(sfi.szTypeName)
   End If

End Function


Public Function TrimNull(startstr As String) As String

  'returns the string up to the first
  'null, if present, or the passed string
   Dim pos As Integer
   
   pos = InStr(startstr, Chr


( 0 )) 如果 pos 然后 TrimNull =左
(0)) If pos Then TrimNull = Left


这篇关于要获取所有文件的列表,请在本地计算机中键入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆