Directory File Count

Posted on 2006-05-08
Last Modified: 2010-04-17
Hi all

I need to count the number of jpg files in a directory (the same directory as the file which will do the counting.)

In ASP! Can anyone do this?
Question by:Zorkinhimerlingling
    LVL 23

    Accepted Solution

    This worked for me:

        Dim FSO
        Dim Files
        Dim File
        Dim Count
        Set FSO = Server.CreateObject("Scripting.FileSystemObject")
        Set Files = FSO.GetFolder(Server.MapPath("./")).Files
        Set FSO = Nothing
        Count = 0
        For Each File In Files
              Select Case LCase(Right(File.Name, 3))
                    Case "jpg"
                      Count = Count + 1
              End Select
        Set File = Nothing
        Set Files = Nothing

    This is based on this example:

    LVL 1

    Author Comment

    Thank you. I had to replace msgbox with response.write, but it does what I need it to do.
    LVL 1

    Author Comment

    Sorry I should of mentioned msgbox returns a permissions denied error
    LVL 23

    Expert Comment

    glad it worked zork

    actually the msgbox was something i forgot to change - I actually ran it as a script on my desktop and had to change a few things to make it work as ASP - forgot to do the msgbox but i'm glad you worked it out


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now