Array Help -URGENT-

Posted on 2006-05-10
Last Modified: 2010-04-16

I dont know alow about arrays in c# but here is what Im trying to do:

I will be scanning a directory tree and I wanted to store the files in an array as well as the directories but I wanted to somehow have an entry in the array for each file that would point to its associated directory so I could later know which files belong in which directory.

Any idea how this could be done... I think I could figure it out with fiddling around however I dont want to create huge memory leaks or anything.

Question by:rushtheweb
    LVL 85

    Accepted Solution

    Create a DirectoryInfo instance for the root folder of your search.

    Then use the GetFiles() method which returns an array of FileInfo instances:

    Store the FileInfo instances in your array:

    Using the FileInfo class you can get just the filename, the directory of the file or the full path, etc...

    You can use the GetDirectories() method to facilitate your recursive search of the directory tree:
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    By the way, I would use an ArrayList to store the FileInfo instances...not an Array.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    759 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

    13 Experts available now in Live!

    Get 1:1 Help Now