how to determine number of files in directory? array question

  • Thread starter Bart Plessers \(artabel\)
  • Start date
B

Bart Plessers \(artabel\)

Hello,

I have an asp script that lists the files in a directory:

CurrentPATH = "c:\temp\"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(CurrentPATH)
Set oFolderContents = oFolder.Files
For Each oFileItem in oFolder.Files
.....
next


However,
before doing the "For..Next" loop, I want to determine the number of files
in oFolderContents.

How can I do this?
Is there another way to determine the number of files in a given directory?

tia

bartp
 
K

Ken Schaefer

The Files collection has a .Count() property that returns the number of
Files in the collection;

obj.Files.Count()

where obj is a Folder object. Check the WSH reference, which you can
download from here:
http://www.microsoft.com/downloads/...48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en

Cheers
Ken



: Hello,
:
: I have an asp script that lists the files in a directory:
:
: CurrentPATH = "c:\temp\"
: Set oFSO = CreateObject("Scripting.FileSystemObject")
: Set oFolder = oFSO.GetFolder(CurrentPATH)
: Set oFolderContents = oFolder.Files
: For Each oFileItem in oFolder.Files
: .....
: next
:
:
: However,
: before doing the "For..Next" loop, I want to determine the number of files
: in oFolderContents.
:
: How can I do this?
: Is there another way to determine the number of files in a given
directory?
:
: tia
:
: bartp
:
:
:
:
:
: --
: HyperART
: Paul Van Ostaijenlaan 4
: 3001 Heverlee
:
:
:
 
B

Bart Plessers \(artabel\)

Hi ken,

thanx for quick reply.

However, I can't get away with the syntax.
Can you clearify a little bit?
Maybe provide the correct syntax for my example below?
: CurrentPATH = "c:\temp\"
: Set oFSO = CreateObject("Scripting.FileSystemObject")
: Set oFolder = oFSO.GetFolder(CurrentPATH)
: Set oFolderContents = oFolder.Files
: For Each oFileItem in oFolder.Files
: .....
: next




tia

bart
 
B

Bart Plessers \(artabel\)

sorry, found it already with your VERY helpfull link!!

syntax:
MyCount = oFolderContents.count

without the brackets...


thanx a lot again

bart
 
K

Ken Schaefer

Sorry about the brackets - I was just "quoting from memory" - obviously I
got it a little bit wrong! Glad you got it working!

Cheers
Ken

: sorry, found it already with your VERY helpfull link!!
:
: syntax:
: MyCount = oFolderContents.count
:
: without the brackets...
:
:
: thanx a lot again
:
: bart
:
:
:
: --
: HyperART
: Paul Van Ostaijenlaan 4
: 3001 Heverlee
:
: : > Hi ken,
: >
: > thanx for quick reply.
: >
: > However, I can't get away with the syntax.
: > Can you clearify a little bit?
: > Maybe provide the correct syntax for my example below?
: >
: > > : CurrentPATH = "c:\temp\"
: > > : Set oFSO = CreateObject("Scripting.FileSystemObject")
: > > : Set oFolder = oFSO.GetFolder(CurrentPATH)
: > > : Set oFolderContents = oFolder.Files
: > > : For Each oFileItem in oFolder.Files
: > > : .....
: > > : next
: >
: >
: >
: >
: > tia
: >
: > bart
: >
: >
: >
: >
: >
: > --
: > HyperART
: > Paul Van Ostaijenlaan 4
: > 3001 Heverlee
: >
: > : > > The Files collection has a .Count() property that returns the number
of
: > > Files in the collection;
: > >
: > > obj.Files.Count()
: > >
: > > where obj is a Folder object. Check the WSH reference, which you can
: > > download from here:
: > >
: >
:
http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-
: > 8A76-1C4099D7BBB9&displaylang=en
: > >
: > > Cheers
: > > Ken
: > >
: > >
: > >
: > > : > > : Hello,
: > > :
: > > : I have an asp script that lists the files in a directory:
: > > :
: > > : CurrentPATH = "c:\temp\"
: > > : Set oFSO = CreateObject("Scripting.FileSystemObject")
: > > : Set oFolder = oFSO.GetFolder(CurrentPATH)
: > > : Set oFolderContents = oFolder.Files
: > > : For Each oFileItem in oFolder.Files
: > > : .....
: > > : next
: > > :
: > > :
: > > : However,
: > > : before doing the "For..Next" loop, I want to determine the number of
: > files
: > > : in oFolderContents.
: > > :
: > > : How can I do this?
: > > : Is there another way to determine the number of files in a given
: > > directory?
: > > :
: > > : tia
: > > :
: > > : bartp
: > > :
: > > :
: > > :
: > > :
: > > :
: > > : --
: > > : HyperART
: > > : Paul Van Ostaijenlaan 4
: > > : 3001 Heverlee
: > > :
: > > :
: > > :
: > >
: > >
: >
: >
:
:
 

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

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top