Iterate through files in a particular folder

Posted on 2006-04-20
Last Modified: 2010-04-23
I am building a website that stores images in a folder with the id of a particular user.  If a user stores more than one picture the folder will look like this

 - 1001_web.jpg
 - 1001_web1.jpg
 - 1001_web2.jpg

Given I have a userid, how can I get a collection of images  that start with that userid?
Question by:rodmjay
    LVL 62

    Expert Comment

    by:Fernando Soto
    Hi rodmjay;

    Try this

            Dim di As New System.IO.DirectoryInfo("FolderPath")
            Dim fi() As System.IO.FileInfo
            fi = di.GetFiles(UserId & "1001_web?..jpg")

            For Each f As System.IO.FileInfo In fi

    LVL 8

    Author Comment

    maybe you could help me a littlw with the search pattern a little bit.

    The userid is the 1001 and there could be other images that are 1001_thumb, etc
    LVL 62

    Accepted Solution

    Hi rodmjay;

    This will return all jpg files for user ID 1001.

        fi = di.GetFiles("1001*.jpg")

    This will return all files in the directory for user 1001.

        fi = di.GetFiles("1001*")


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    754 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

    20 Experts available now in Live!

    Get 1:1 Help Now