• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • 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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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