根据您的操作系统和要求,您可能会发现搜索 SystemIndex 很有用。这里有一些注意事项。
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSQL As String
''This is the Windows Search connection string to use
cn.Open "Provider=Search.CollatorDSO;" _
& "Extended Properties='Application=Windows';"
''SQL SELECT statement specifies what properties to return,
'' you can add more if you want
'' FROM - use SystemIndex for a local query or
'' MACHINENAME.SystemIndex for remote
'' WHERE - specify restrictions including SCOPE and other
'' conditions that must be true
''To add scope restriction:
''strSQL = "SELECT System.ItemName, System.ItemTypeText, " _
'' & "System.Size FROM SystemIndex " _
'' & "WHERE Scope='file:c:\Users\'"
strSQL = "SELECT System.ItemName, System.ItemTypeText, " _
& "System.Size, System.ItemFolderPathDisplay " _
& "FROM SystemIndex " _
& "WHERE System.ItemName='AnExampleFile.mdb'"
rs.Open strSQL, cn
rs.MoveFirst
Do Until rs.EOF
Debug.Print rs.Fields.Item("System.ItemName")
Debug.Print rs.Fields.Item("System.ItemTypeText")
Debug.Print rs.Fields.Item("System.Size")
Debug.Print rs.Fields.Item("System.ItemFolderPathDisplay")
Debug.Print String(30, "-")
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
更多信息: http:
//msdn.microsoft.com/en-us/library/bb266517 (VS.85).aspx
http://msdn.microsoft.com/en-us/library/bb419046(v=VS.85 ).aspx
http://msdn.microsoft.com/en-us/library/bb776859(v=VS.85).aspx
http://msdn.microsoft.com/en-us/library/bb231297(v=VS .85).aspx