Solved

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

Posted on 2009-04-06
5
159 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 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Python - ImportError: No module named 'urllib2' 2 219
Update a File not in all folders 2 46
Windows Batch File - Combing output in a single line 3 66
ROBOFTP UNZIP 1 46
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…
Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

810 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