Applying procedure to every file on a drive

Question:

For EVERY filename present on a hard drive, I need to convert the path and filename to a string and then evaluate the string for certain conditions. If those conditions are True, modify the string and append the string to “DataBase.txt. Otherwise, skip the file and move on to the next file, etc.

My program will successfully do this with one file at a time, but I don’t want to have to manually go through every file on the hard drive.How do I tell the program how to get every file on the drive? (Do first dir in C: then do and subdirs in that dir..ad nauseum…then do second dir in C; and so on.)

Thanks,
Rocky

Answer:

While a small ISAPI component would run faster, you can get away with a littlerecursive VBScript and the FileSystemObject. If you have a large number of files on thedrive, you may need to extend the script’s timeout. Here’s some code for doing that:

Set fs = CreateObject("Scripting.FileSystemObject")
Call ShowFolderList("c:")
Set fs=Nothing

Sub ShowFolderList(folderspec)
On error resume next
Set f = fs.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
   ' Do any processing of the filename and path here
   ' For demonstration, this displays the filename and path
   ' If you want just the filename use f1.Name
Response.Write f1.Path & "
"
Next
Set fc2 = f.SubFolders
For Each f1 in fc2
   ShowFolderList(f1.Path)
Next
End Sub

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS