Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7954381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:24:46+00:00 2026-06-04T03:24:46+00:00

i needed to filter out the whole computer and find only .sto files. I

  • 0

i needed to filter out the whole computer and find only .sto files. I want theses files displayed in a listbox. I am needing them displayed like this: “text.sto”. I am using Visual C# Express. How do i do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T03:24:48+00:00Added an answer on June 4, 2026 at 3:24 am

    Make sure you have this using directive at the top of your code file:

    using System.IO;
    

    Get the directories with this method:

    string[] dirs = Directory.GetFiles(@"c:\", "*.sto", SearchOption.AllDirectories);
    

    It takes a second parameter that allows you to filter the results. More information on the method can be found here: http://msdn.microsoft.com/en-us/library/ms143316.aspx

    Incase you do not want to use the built in .Net function for this (because it can throw access errors and provide no results), here is a answer to the question that shows doing it a different way: https://stackoverflow.com/a/929418/184746

    Referencing from the aforementioned article, here is a method that will catch and wont give you errors with filtering added for *.sto:

    public static IEnumerable<string> GetFiles(string path)
    {
        Queue<string> queue = new Queue<string>();
        queue.Enqueue(path);
        while (queue.Count > 0)
        {
            path = queue.Dequeue();
            try
            {
                foreach (string subDir in Directory.GetDirectories(path))
                {
                    queue.Enqueue(subDir);
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex);
            }
            string[] files = null;
            try
            {
                files = (from f in Directory.GetFiles(path)
                         where f.EndsWith(".sto")
                         select f).ToArray();
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex);
            }
            if (files != null)
            {
                foreach (string t in files)
                {
                    yield return t;
                }
            }
        }
    }
    

    You can use it like this:

    string[] dirs = GetFiles(@"c:\").ToArray();
    

    After that, create a listbox in the designer, and iterate through and add the items

    foreach(var f in dirs)
    {
        listBox1.Items.Add(String.Format("\"{0}\"", f));
    }
    

    Out of curiosity, what was your search parameter when researching this? Because a simple google search reveals all you need: "get list of files C#"https://www.google.ca/search?sourceid=chrome&ie=UTF-8&q=get+list+of+files+C%23

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pulling JSON data fromlocalstorage and using grep to filter out the items needed
I have a .infodiv class with say 4 elements. I want to filter out
I needed a method to filter out all elements that are parents of other
I needed to find and use the coordinates of the intersection of a cubic
I need to filter my table so it only uses the minimum amount of
I have an array of hashes, and I want the unique values out of
I have a list of names in a box that I want to filter
Needed Finfo but deleted msi package, so uninstalled php 5.3.0, downloaded 5.3.2 and installed.
I needed to update the system tray icon's text value, of my application, whenever
I needed to use in my old Git similar settings to the following to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.