469,623 Members | 938 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,623 developers. It's quick & easy.

how to determine number of files in directory? array question

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

Jul 19 '05 #1
4 11666
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/d...displaylang=en

Cheers
Ken

"Bart Plessers (artabel)" <ba**********@hotmail.com> wrote in message
news:eN**************@TK2MSFTNGP10.phx.gbl...
: 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
:
:
:
Jul 19 '05 #2
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

"Ken Schaefer" <ke*******@THISadOpenStatic.com> wrote in message
news:e#**************@tk2msftngp13.phx.gbl... 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/d...C48-207D-4BE1-
8A76-1C4099D7BBB9&displaylang=en
Cheers
Ken

"Bart Plessers (artabel)" <ba**********@hotmail.com> wrote in message
news:eN**************@TK2MSFTNGP10.phx.gbl...
: 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
:
:
:

Jul 19 '05 #3
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

"Bart Plessers (artabel)" <ba**********@hotmail.com> wrote in message
news:#i**************@TK2MSFTNGP09.phx.gbl...
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

"Ken Schaefer" <ke*******@THISadOpenStatic.com> wrote in message
news:e#**************@tk2msftngp13.phx.gbl...
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/d...C48-207D-4BE1- 8A76-1C4099D7BBB9&displaylang=en

Cheers
Ken

"Bart Plessers (artabel)" <ba**********@hotmail.com> wrote in message
news:eN**************@TK2MSFTNGP10.phx.gbl...
: 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
:
:
:


Jul 19 '05 #4
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

"Bart Plessers (artabel)" <ba**********@hotmail.com> wrote in message
news:O6**************@tk2msftngp13.phx.gbl...
: 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
:
: "Bart Plessers (artabel)" <ba**********@hotmail.com> wrote in message
: news:#i**************@TK2MSFTNGP09.phx.gbl...
: > 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
: >
: > "Ken Schaefer" <ke*******@THISadOpenStatic.com> wrote in message
: > news:e#**************@tk2msftngp13.phx.gbl...
: > > 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/d...C48-207D-4BE1-
: > 8A76-1C4099D7BBB9&displaylang=en
: > >
: > > Cheers
: > > Ken
: > >
: > >
: > >
: > > "Bart Plessers (artabel)" <ba**********@hotmail.com> wrote in message
: > > news:eN**************@TK2MSFTNGP10.phx.gbl...
: > > : 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
: > > :
: > > :
: > > :
: > >
: > >
: >
: >
:
:
Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Shawn Mehaffie | last post: by
27 posts views Thread by the other john | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.