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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to dynamically set the form action using jQuery.

757 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

17 Experts available now in Live!

Get 1:1 Help Now