|
 |
pro_vb thread: Parse through a Folder and its Subfolders and all the Files
Message #1 by "Brett Moyer" <brett.moyer@c...> on Tue, 18 Feb 2003 20:25:32
|
|
Hi Brett
I use the following code to find files in a directory (this is a modified
version of the code that I got from MS), you can insert this code into a COM
object and call it from your ASP page.
Good luck.
Regards,
Stephen
Function FindFiles(FindStr as String, Optional Path As String = "c:\")
Dim FileName As String ' Walking filename variable.
Dim DirName As String ' SubDirectory Name.
Dim dirNames() As String ' Buffer for directory name entries.
Dim nDir As Integer ' Number of directories in this path.
Dim i As Integer ' For-loop counter.
Dim FindStr As String
Dim FileSize As Long
Dim NumFiles As Integer
Dim NumDirs As Integer
Dim DirCount As Integer
'This function searches the HDD for a specified file.
'This is to find the path for the application so that it can be called
'
'This function is called for every sub directory in
'every directory found, so there could be hundreds of
'instances of this function alive, these must be stopped
'if the file has been found - add your own break in the code
On Error GoTo sysFileERR
If Right(Path, 1) <> "\" Then Path = Path & "\"
' Search for subdirectories.
nDir = 0
ReDim dirNames(nDir)
DirName = Dir(Path, vbDirectory Or vbHidden Or vbArchive Or vbReadOnly
Or vbSystem) ' Even if hidden, and so on.
Do While Len(DirName) > 0
' Ignore the current and encompassing directories.
If (DirName <> ".") And (DirName <> "..") Then
' Check for directory with bitwise comparison.
DoEvents
'End If
If GetAttr(Path & DirName) And vbDirectory Then
dirNames(nDir) = DirName
DirCount = DirCount + 1
nDir = nDir + 1
ReDim Preserve dirNames(nDir)
End If ' directories.
sysFileERRCont:
End If
DirName = Dir() ' Get next subdirectory.
Loop
' Search through this directory and sum file sizes.
FileName = Dir(Path & FindStr, vbNormal Or vbHidden Or vbSystem _
Or vbReadOnly Or vbArchive)
While Len(FileName) <> 0
'Found the file!
'Save the name and path to the global var
sApplicationExePath = Path & FileName
'exit the function to stop searching
Exit Function
Wend
' If there are sub-directories..
If nDir > 0 Then
' Recursively walk into them
For i = 0 To nDir - 1
FindFiles Path & dirNames(i) & "\"
Next i
End If
AbortFunction:
Exit Function
sysFileERR:
If Right(DirName, 4) = ".sys" Then
Resume sysFileERRCont ' Known issue with pagefile.sys
Else
MsgBox "Error: " & Err.Number & " - " & Err.Description, , _
"Unexpected Error"
Resume AbortFunction
End If
End Function
-----Original Message-----
From: Brett Moyer [mailto:brett.moyer@c...]
Sent: Tuesday, February 18, 2003 10:26 PM
To: professional vb
Subject: [pro_vb] Parse through a Folder and its Subfolders and all the
Files
Hello,
Is it possible to create a program that can Parse through a Folder and its
Subfolders and all the Files contained therein?
I have a Folder with several subfolders and Tons of files and I want to
create a Table of Contents/Index for it, because it is a nightmare.
Can I use an ASP page online to run this program and then reurn the
results to that ASP page displaying the results?
Help ?
Thank you
******** Appleton Limited *********
This entire electronic mail message is confidential and is issued for information purposes only to the addressee, being a business
associate of Appleton Limited Reg. No 1999/004031/06 or of its subsidiaries. The message and attachments if any is subject to
copyright and may not be reproduced in whole or in part without the written permission of Appleton Limited. Opinions and
recommendations contained herein are and must be construed solely as statements of opinion and not statements of fact. Unless
specifically stated, Appleton Limited gives no warranty, expressed or implied, as to the accuracy, timeliness, completeness, or
fitness for any purpose of any information contained within this e-mail.
***********************************
|
|
 |