Home
Manage Your Code
Snippet: DirectoryEnumerator (C#)
Title: DirectoryEnumerator Language: C#
Description: Enumerates all subdirectories of a specified directory. Views: 266
Author: Diego Guidi Date Added: 5/5/2006
Copy Code  
1using System;
2using System.Collections;
3using System.IO;
4
5namespace TerraNova.PocketShArc
6{
7	/// <summary>

8	/// Espone tutte le sottodirectory che sono in una specifica directory.

9	/// Espone la directory stessa come primo elemento dell'enumerazione.

10	/// </summary>	

11	/// <seealso cref="Directory" />	

12	/// <seealso cref="DirectoryInfo" />

13	public class DirectoryEnumerator : IEnumerable, IEnumerator
14	{
15		// Memorizzo la directory di partenza, per le chiamate a IEnumerator.Reset		

16		private readonly DirectoryInfo startDir = null;
17
18		// Contiene tutte le sottodirectory

19		private ArrayList dirs = null;
20				
21		// Enumeratore alle singole directory

22		private IEnumerator ienum = null;
23
24		/// <summary>

25		/// inizializza una nuova istanza della classe<see cref="DirectoryEnumerator"/>.

26		/// </summary>

27		public DirectoryEnumerator(string dirPath)
28		{
29			if (!Directory.Exists(dirPath))
30				throw new ArgumentException("The specified directory not exists!", "dirPath");
31						
32			startDir = new DirectoryInfo(dirPath);
33			Reset();
34		}
35				#region IEnumerable   ...		#endregion
46		#region IEnumerator   ...		#endregion
94		#region Metodi		   ...		#endregion
105	}
106}
107