File Search

J

Jonathan

Hi,
What I am trying to do is have a procedure display a
dialog that allows a user to select a folder. The
procedure then writes in the document a list of all files
in the selected folder and its subfolders.

I can get this to work successfully for the selected
folder. But not to work for subfolders.

I am trying to use the Application.FileSearch.SearchScopes
example in OnlineHelp. Unfortunitely I can't figure out
how to set the start/base folder.

Any ideas or suggestions appreciated :)

Cheers
Jonathan
 
H

Helmut Weber

Hi Jonathan,
how about that? Refining the input possibilities
is up to you.
Sub FileDiver()
Dim iCN As Integer ' Counter
Dim sFN As String ' Filename
Dim oFS As Object ' Filesearch
Dim sPt As String ' start path
Set oFS = Application.FileSearch
sPt = InputBox("StartPath")
sPt = Chr$(34) & sPt & Chr$(34)
With oFS
.LookIn = sPt
.FileName = "*.doc"
.SearchSubFolders = True
.Execute
For iCN = 1 To .FoundFiles.Count
sFN = Format(iCN, "0000")
sFN = sFN & Chr$(9)
sFN = sFN & .FoundFiles(iCN) & Chr$(13)
Selection.TypeText sFN
Next iCN
End With
End Sub
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, NT4.0
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top