Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you enumerate a specific set of files

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I've got a directory - C:\images - filled with stuff. In that directory are files named fred1.tga, fred2.tga, fred3.tga... I want to create a collection of objects that represent files named fred*.tga so that I can access FileSize and CreationDate in a loop. How do I do it?
 
this will enumerate all the files in a folder


strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService. _
ExecQuery("Select * from CIM_DataFile where Path = '\\Scripts\\'")
For Each objFile in colFiles
Wscript.Echo objFile.Name
Next



Regards
Steve Friday
 
Thanks Steve,
I was able to get that far using one of Microsofts example scripts, but what I was wondering, is how to create a collection of only the fred*.tga files.
 
Can you not just issue an if statement within the FOR Each section to pick out your files,

IE
For Each objFile in colFiles
IF mid(objfile.name,11,4) = "fred" _
and right (objfile.name,3) = tag then
msgbox objfile.name & " " & objFile.LastAccessed
End If
Next


presuming mid(objfile.name,11,4) = C:\scripts\fred



Regards
Steve Friday
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top