Something that does SELECT's to get info about a file or directory? Something that actually works?
Language doesn't matter, I'm most interested in the query syntax.
Something that does SELECT's to get info about a file or directory? Something that actually works?
Language doesn't matter, I'm most interested in the query syntax.
This tool WMI Code Creator have some help.
See this code :
strComputer = "."
Set objWMIService = GetObject("winmgmts:\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM CIM_DataFile",,48)
For Each objItem in colItems
Wscript.Echo "-----------------------------------"
Wscript.Echo "CIM_DataFile instance"
Wscript.Echo "-----------------------------------"
Wscript.Echo "AccessMask: " & objItem.AccessMask
Wscript.Echo "Archive: " & objItem.Archive
Wscript.Echo "LastAccessed: " & objItem.LastAccessed
Wscript.Echo "LastModified: " & objItem.LastModified
Wscript.Echo "Manufacturer: " & objItem.Manufacturer
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "Path: " & objItem.Path
Wscript.Echo "Readable: " & objItem.Readable
Wscript.Echo "Status: " & objItem.Status
Wscript.Echo "System: " & objItem.System
Wscript.Echo "Version: " & objItem.Version
Wscript.Echo "Writeable: " & objItem.Writeable
Next
[EDIT]
This sample is that you are looking Enumerating All the Files on a Computer.
Try this format of query to :
"Select * From Win32_Directory Where FileName = 'Scripts'"
Here more info about make query WQL using LIKE.
Here're some examples:
Querying a file:
SELECT * FROM CIM_DataFile WHERE Name='C:\\WINDOWS\\NOTEPAD.EXE'
SELECT * FROM CIM_DataFile WHERE Drive='C:' AND Path='\\Windows\\' AND FileName='Notepad' AND Extension='EXE'
Querying a folder:
SELECT * FROM CIM_Directory WHERE Name='C:\\Windows'
SELECT * FROM CIM_Directory WHERE Drive='C:' AND Path='\\Program Files\\' AND FileName='Internet Explorer'
For more information on the query syntax, see WQL (SQL for WMI). Also see CIM_DataFile
and CIM_Directory
for a list of file and folder properties that can be used in the SELECT
and WHERE
clauses.
I have reached the answer, and it was all caused by a silly error of mine: I was failing to double the backslashes in the path string, and thinking it was being done. Additionally, you have to specify all four fields in the WHERE clause: drive, path, filename, and extension.