Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Active Server Pages (ASP)
Expertise: Beginner
Aug 30, 1998



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Applying procedure to every file on a drive


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.)



While a small ISAPI component would run faster, you can get away with a little recursive VBScript and the FileSystemObject. If you have a large number of files on the drive, 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 & "
Set fc2 = f.SubFolders
For Each f1 in fc2
End Sub

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date