Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default Searching directories...


"Forrest" wrote in message
...
I need to find all of a few types of files on a disc or
CD; I assume the best way is to start at the route
directory, then scan each folder? But there are folders
within folders ( about three levels deep ), so I'm
running into trouble.

How do I do this...?

Thanks.


You can write a recursive search

example

Function GetRecursiveFileList(Startpoint As String, FileExtension As String,
filelist() As String, FileCount As Long) As Long
' ----------------------------------------
' Routine scans filesystem recursively for
' files with specified extension
' ----------------------------------------
Dim file_name As String
Dim FIndent As Integer, FIndex As Integer
Dim File_Path As String, StrtPath As String
Dim File_Read As Integer
Dim x As Boolean, xTemp As Integer, S$
Dim i As Integer, ierr As Long
On Error Resume Next
FIndent = FIndent + 1
If Right(Startpoint, 1) < "\" Then
File_Path = Startpoint & "\"
Else
File_Path = Startpoint
End If

file_name = Dir$(File_Path, vbDirectory + vbReadOnly + vbArchive)
File_Read = 1
Dim FileNameToAdd As String
Dim IsDirectory As Boolean
x = False
Const CustomTabs = vbTab
File_Read = 1

Do While file_name < ""
If file_name < "." And file_name < ".." Then
IsDirectory = (GetAttr(File_Path & file_name) = vbDirectory) Or
(GetAttr(File_Path & file_name) = vbDirectory + vbArchive) _
Or (GetAttr(File_Path & file_name) = vbDirectory + vbReadOnly) _
Or (GetAttr(File_Path & file_name) = vbDirectory + vbReadOnly +
vbArchive)

FileNameToAdd = ""


'Check for file types


If IsDirectory = False Then
If UCase(Right(file_name, Len(file_name) - InStr(file_name,
"."))) = UCase(FileExtension) Then
FileNameToAdd = File_Path & file_name
End If

If FileNameToAdd < "" Then
filelist(FileCount) = FileNameToAdd
FileCount = FileCount + 1
End If

Else
If IsDirectory Then 'Perform recursive
'MsgBox "Searching directory :" & File_Path & file_name
StrtPath = File_Path & file_name
ierr = GetRecursiveFileList(StrtPath, FileExtension,
filelist(), FileCount)
End If
End If
x = True
' FIndex = FIndex + 1
End If

If x Then
file_name = Dir$(File_Path, vbDirectory + vbArchive +
vbReadOnly)
For i = 2 To File_Read
file_name = Dir$
Next i
x = False
End If
file_name = Dir$

If file_name = "" Then
file_name = Dir$(, vbReadOnly)
End If
File_Read = File_Read + 1

Loop
FIndent = FIndent - 1

End Function


Keith


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Searching, matching then searching another list based on the match A.S. Excel Discussion (Misc queries) 1 December 13th 06 05:08 AM
Simplify changing directories BobS9895 Excel Worksheet Functions 0 July 18th 06 07:22 PM
creating directories freekrill Excel Discussion (Misc queries) 1 July 25th 05 09:26 AM
Searching directories... Phobos Excel Programming 0 August 1st 03 12:03 AM
Listing files in directories. skmr3 Excel Programming 0 July 11th 03 12:50 AM


All times are GMT +1. The time now is 02:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"