On 19 Dec 2006 03:54:34 -0800, "sam" <sameersrivastava2k@gmail.com>
wrote:
I think the FileSearch object is a bit limited. Here is similar code
using the more powerful FileSystemObject:
Private Function fsoCountFiles(ByVal strDir As String)
Dim fso As Scripting.FileSystemObject
Dim folder As Scripting.folder
Dim file As Scripting.file
Set fso = New Scripting.FileSystemObject
Set folder = fso.GetFolder(strDir)
For Each file In folder.Files
Me.List4.AddItem (file.Name)
Next file
Set file = Nothing
Set folder = Nothing
Set fso = Nothing
End Function
Then the double-click event:
Private Sub List4_DblClick(Cancel As Integer)
Dim strFullName As String
'Text0 has the root for the search.
strFullName = Me.Text0.Value & "\" &
List4.ItemData(List4.ListIndex)
Application.FollowHyperlink strFullName
End Sub
-Tom.
Quote:
>Hi all,
>
>Kindly have a look to the code given below
>************************************************* ****************************
>Public Function CountFiles(strDir As String, Optional SubDir As
>Boolean) As Long
>
>With Application.FileSearch
.NewSearch
.LookIn = strDir
.FileName = "*.*"
.SearchSubFolders = SubDir
>
>
If .Execute 0 Then
CountFiles = .FoundFiles.count
End If
>
For i = 1 To .FoundFiles.count
Me.list1.AddItem (.FoundFiles(i))
Next i
>
>End With
>End Function
>************************************************* ***********************
>you must have understood that this code is helping me to count the
>number of files in a given folder and adding the names of those files
>in a listbox.
>It is adding the file name in the list box as
>"I:\folder1\subfolder1\file1.doc"
>but i want the name to be added in the list box as "file1.doc"
>
>My second question is , is it possible to open the same file in the
>list box by double clicking the filename.
>
>can any one give me the solution for the problem.
>
>sam
|