Solved

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

Posted on 2009-04-06
5
162 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
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 dynamically set the form action using jQuery.

623 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