PC Review


Reply
Thread Tools Rate Thread

Count the Number of Files in a Folder

 
 
Jim
Guest
Posts: n/a
 
      2nd Mar 2010
I’m sorry if this is a repost, I posted the same question yesterday but it
never appeared on the site.

Could someone please show me an example or examples of how to return the
number of files in a folder? I don’t need anything except the total number
of files in the folder. I’d like to use VB but, I’m open to any solution…

Thanks in advance,

Jim


 
Reply With Quote
 
 
 
 
Alex Dybenko
Guest
Posts: n/a
 
      2nd Mar 2010
Hi,
something like this:

strFile = dir("c:\*.*")
do while len(strFile)>0
I=I+1
strFile=dir
loop

debug.print I

--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com


"Jim" <(E-Mail Removed)> wrote in message
news:104A3781-C5E1-446A-80B1-(E-Mail Removed)...
> I’m sorry if this is a repost, I posted the same question yesterday but it
> never appeared on the site.
>
> Could someone please show me an example or examples of how to return the
> number of files in a folder? I don’t need anything except the total
> number
> of files in the folder. I’d like to use VB but, I’m open to any solution…
>
> Thanks in advance,
>
> Jim
>
>

 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      2nd Mar 2010
Try this:
Sub Demo()

MsgBox FileCountA("C:\temp\")
MsgBox FileCountB("C:\temp\")

End Sub

Function FileCountA(Path As String) As Long
Dim strTemp As String
Dim lngCount As Long

strTemp = Dir(Path & "*.*")
Do While strTemp <> ""
lngCount = lngCount + 1
strTemp = Dir
Loop

FileCountA = lngCount

End Function
Function FileCountB(Path As String) As Long

Dim objFSO As Object

Set objFSO = CreateObject("Scripting.FileSystemObject").GetFolder(Path)
FileCountB = objFSO.Files.Count

Set objFSO = Nothing

End Function

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Alex Dybenko" wrote:

> Hi,
> something like this:
>
> strFile = dir("c:\*.*")
> do while len(strFile)>0
> I=I+1
> strFile=dir
> loop
>
> debug.print I
>
> --
> Best regards,
> ___________
> Alex Dybenko (MVP)
> http://accessblog.net
> http://www.PointLtd.com
>
>
> "Jim" <(E-Mail Removed)> wrote in message
> news:104A3781-C5E1-446A-80B1-(E-Mail Removed)...
> > I’m sorry if this is a repost, I posted the same question yesterday but it
> > never appeared on the site.
> >
> > Could someone please show me an example or examples of how to return the
> > number of files in a folder? I don’t need anything except the total
> > number
> > of files in the folder. I’d like to use VB but, I’m open to any solution…
> >
> > Thanks in advance,
> >
> > Jim
> >
> >

> .
>

 
Reply With Quote
 
Jim
Guest
Posts: n/a
 
      2nd Mar 2010
Thanks, function FileCountB works great!

Jim

"ryguy7272" wrote:

> Try this:
> Sub Demo()
>
> MsgBox FileCountA("C:\temp\")
> MsgBox FileCountB("C:\temp\")
>
> End Sub
>
> Function FileCountA(Path As String) As Long
> Dim strTemp As String
> Dim lngCount As Long
>
> strTemp = Dir(Path & "*.*")
> Do While strTemp <> ""
> lngCount = lngCount + 1
> strTemp = Dir
> Loop
>
> FileCountA = lngCount
>
> End Function
> Function FileCountB(Path As String) As Long
>
> Dim objFSO As Object
>
> Set objFSO = CreateObject("Scripting.FileSystemObject").GetFolder(Path)
> FileCountB = objFSO.Files.Count
>
> Set objFSO = Nothing
>
> End Function
>
> --
> Ryan---
> If this information was helpful, please indicate this by clicking ''Yes''.
>
>
> "Alex Dybenko" wrote:
>
> > Hi,
> > something like this:
> >
> > strFile = dir("c:\*.*")
> > do while len(strFile)>0
> > I=I+1
> > strFile=dir
> > loop
> >
> > debug.print I
> >
> > --
> > Best regards,
> > ___________
> > Alex Dybenko (MVP)
> > http://accessblog.net
> > http://www.PointLtd.com
> >
> >
> > "Jim" <(E-Mail Removed)> wrote in message
> > news:104A3781-C5E1-446A-80B1-(E-Mail Removed)...
> > > I’m sorry if this is a repost, I posted the same question yesterday but it
> > > never appeared on the site.
> > >
> > > Could someone please show me an example or examples of how to return the
> > > number of files in a folder? I don’t need anything except the total
> > > number
> > > of files in the folder. I’d like to use VB but, I’m open to any solution…
> > >
> > > Thanks in advance,
> > >
> > > Jim
> > >
> > >

> > .
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i count the number of mails in a perticular folder? Jeevan Microsoft Outlook Discussion 2 6th May 2010 03:21 PM
Count number of files in a folder CAM Microsoft Excel Programming 2 13th Oct 2006 05:12 AM
Count the number of hidden files and directories =?Utf-8?B?RGFsZQ==?= Microsoft C# .NET 3 21st Oct 2004 06:53 PM
Is there a quick way to count the number of files in a folder? Elflan Windows XP Basics 5 9th Feb 2004 02:14 PM
How to count Number of Test Case Variations in .WSF files GNRaj Windows XP Logo 1 19th Dec 2003 05:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:29 PM.