how do i search a whole computer for a particular type of file in vbscript?

Posted on 2009-04-06
Last Modified: 2013-10-08
Hi there,
i was wondering how can i modify my script to search a whole computer, not just one hard drive
Set objfso = CreateObject("Scripting.FileSystemObject")

objStartFolder = "" 

Dim obbjFiletxt, sFilename, sPath 

Set objFilesys = CreateObject("Scripting.FileSystemObject") 

Set objFiletxt = objfso.CreateTextFile("d:\inventory.txt", True) 

sPath = objfso.GetAbsolutePathName("d:\inventory.txt") 

sFilename = objfso.GetFileName(sPath) 

Set objFolder = objfso.GetFolder(objStartFolder)

	For Each objFile In objFolder.Files

		If objfso.GetExtensionName(objFile) = "jpg" Then


		End If



Open in new window

Question by:nathanlukewong
  • 2
LVL 38

Expert Comment

ID: 24077603
You can get all of the local hard drive letters using a WMI query like this:

On Error Resume Next

Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")

Set colItems = objWMIService.ExecQuery("SELECT DeviceID FROM " &_

    "Win32_LogicalDisk WHERE DriveType = 3")

intLimit = 0

For Each objItem In colItems

    ReDim Preserve arrDrives(intLimit)

    arrDrives(intLimit) = objItem.DeviceID

    intLimit = intLimit + 1


For Each strDrive in arrDrives

    WScript.Echo strDrive

    'Do stuff here


Open in new window


Author Comment

ID: 24077644
unfortunatly i cant use WMI needs to be using FileSystemObject
is it possible?
LVL 38

Accepted Solution

Shift-3 earned 500 total points
ID: 24078166
Your teacher was pretty specific about that eh?  Oops, I mean boss.
 Yes, it is possible.  Take a look at the Drives property of FileSystemObject and the properties of the Drive object.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now