|
-
Oct 12th, 2000, 02:05 AM
#1
Thread Starter
Addicted Member
I want to retrieve the number of files with the extention ".txt" in a folder.
Can somebody help me on this?
Tnx.
Dennie
-
Oct 12th, 2000, 02:50 AM
#2
Lively Member
Add a FileListBox to your form, set the path (file1.path) to be the folder you are looking at. Set the pattern (file1.pattern) to *.txt, then just do file1.listcount to return the number of txt files.
-
Oct 12th, 2000, 05:04 AM
#3
Fanatic Member
Try this ...
Code:
Private Function GetNumberOfFiles(ByVal FolderName As String, _
ByVal Extension As String) As Long
Dim strFile As String
Dim lngCount As Long
lngCount = 0
strFile = Dir(FolderName, vbNormal Or vbReadOnly Or vbHidden Or vbSystem)
Do Until strFile = ""
If Right$(strFile, 3) = Extension Then lngCount = lngCount + 1
strFile = Dir
Loop
GetNumberOfFiles = lngCount
End Function
Call with ...
Code:
lngResult = GetNumberOfFiles("c:\SomeFolder\", "txt")
MsgBox lngResult
Hope this helps.
VB6 sp5, SQL Server 2000, C#
There are no stupid questions. Only stupid people. 
-
Oct 12th, 2000, 05:46 AM
#4
Member
Good code but very slow
You should use the FindFiles API instead. This ones much faster but depending on the search area size, may take some time to.
The code is long for it but is availabel on good VB-Code sites. Try:
http://www.planet-source-code.com/xq...s/ShowCode.htm
A mind is like a parachute, it has to open to let it work
www.2beesoft.com for Icon Manager with over 20.000 free icons
VB6 Ent. SP4, ASP, W2000/W98
-
Oct 12th, 2000, 07:14 AM
#5
_______
<?>
'just a plain and simple count (No Extras)
Code:
Private Sub Form_Load()
'access all files within a folder
Dim stFile As String
Dim stDir As String
Dim i As Integer
stDir = "C:\My Documents\" 'the folder to search
stFile = Dir$(stDir & "*.txt") 'type of files to select
Do While stFile <> ""
i = i + 1
stFile = Dir
Loop
'do what you want to with the information supplied
MsgBox "There are " & i & " files in " & _
stDir & " of txt type."
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|