| |
kearsing
Posts: 1
Score: 0
Joined: 12/11/2001
From: USA
Status: offline
|
I was recently challenged to create a VBScript that would search our entire domain (1750 systems) for the existence of a file and return the location of that file to a text file. At first I thought this might be an easy task. Surely VBScript provides a method that would search through all the sub-folders on a specified drive. I could simply pass a text file of all our system names to the script, search for the file, and spit the info out to a text file. This was not the case though. The extiveness of The FileSystemObject was limited to searching only specified folders. And when I say searching, I use the term loosely. I designed my own searching function (compare a string to the current file and return 'found' if strings match). I found that if I wanted to parse through an entire drive I had to create a recursive function that would bind to a root folder (rootFolder.Getfolder(c:)), search that root folder, then bind to the root folder's subfolders (Set rootFolder = rootFolder.subfolders), search those subfolders, and if the file is still not found the function would call itself passing itself the current subfolder as a root folder parameter. 'For Each Next' was an excellent tool for this. It let me traverse each collection of sub directories before continuing on to the next directory at the root level. I am proud of my personal triumph, for I have not written any practical recursive algorithms prior to this script (I am not counting CSC 330; Advanced Data Structures as practical application). However I am certain that someone has a better, more eloquent method of performing this very task. In actuality my script is pretty slow. If the file is towards the end of the directory structure the script takes awhile to return an answer. The Big O average must be N/2 (N = number of files on drive) comparisons. Any efficiency suggestions out there???
|
|