• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

Array Help -URGENT-


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.

  • 2
1 Solution
Mike TomlinsonMiddle School Assistant TeacherCommented:
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:
Mike TomlinsonMiddle School Assistant TeacherCommented:
By the way, I would use an ArrayList to store the FileInfo instances...not an Array.

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now