Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-04-06
5
Medium Priority
?
166 Views
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
			objFiletxt.WriteLine(objFile) 
		End If
	Next
objFiletxt.Close'

Open in new window

0
Comment
Question by:nathanlukewong
  • 2
5 Comments
 
LVL 38

Expert Comment

by:Shift-3
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
Next
 
For Each strDrive in arrDrives
    WScript.Echo strDrive
    'Do stuff here
Next

Open in new window

0
 

Author Comment

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

Accepted Solution

by:
Shift-3 earned 2000 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.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

972 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