Quick Search for:  in language:    
method,walks,directory,structure,without,recu
   Code/Articles  |  Newest/Best  |  Community  |  Jobs  |  Other  |  Goto  | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
.Net Stats

 Code: 140,189. lines
 Jobs: 383. postings

 How to support the site

 
Sponsored by:

 
You are in:
 

Does your code think in ink?
Login





Latest Code Ticker for .Net.
Click here to see a screenshot of this code!LAME .NET Decoder Component
By Jorge Rodrigues Silva on 11/28

(Screen Shot)

Ping multiple machines
By Juan Pieterse on 11/28


Create Charts with managed code using OWC10, and save as gif
By Juan Pieterse on 11/28


tungFlickeringL ight v1.0 (Active X)
By Nguyen Thanh Tung on 11/28


tungGradientPro gressBar v1.0
By Nguyen Thanh Tung on 11/28


tungDigitalWatc h v1.0
By Nguyen Thanh Tung on 11/28


CalcBytes
By Lewis Moten on 11/27


tungChronometer (ActiveX)
By Nguyen Thanh Tung on 11/27


tungActiveChart (ActiveX)
By Nguyen Thanh Tung on 11/27


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

File System Directory Walker (Recursive)

Print
Email
 

Submitted on: 11/21/2003 6:41:19 PM
By: Danny Campbell 
Level: Intermediate
User Rating: Unrated
Compatibility:C#

Users have accessed this code 226 times.
 
 
     The method walks a directory structure without recursion. Uses the Stack and ArrayList object found in System.Collections.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    //**************************************
    //     
    // Name: File System Directory Walker (R
    //     ecursive)
    // Description:The method walks a direct
    //     ory structure without recursion. Uses th
    //     e Stack and ArrayList object found in Sy
    //     stem.Collections.
    // By: Danny Campbell
    //
    // Inputs:System.String : path  This is
    //     the path to start searching at and is in
    //     cluded in the return.
    System.Boolean : sort  Turns sorting on and off.
    //
    // Returns:System.String[] : The array o
    //     f fully qualified directory names.
    //
    // Assumes:Have not compared function ca
    //     ll recursion using any miscellaneous ben
    //     chmarks code, just thought it may be a u
    //     seful way of processing.
    JUST DON'T BE TOO HARD ON ME.
    //
    // Side Effects:Very useful to cut back 
    //     on STACK space usage
    //
    //This code is copyrighted and has    // limited warranties.Please see http://
    //     www.Planet-Source-Code.com/vb/scripts/Sh
    //     owCode.asp?txtCodeId=1800&lngWId;=10    //for details.    //**************************************
    //     
    
    /// <summary>
    /// Gets a recursive listing of all fold
    //     ers.
    /// </summary>
    /// <param name="path">The path to
    //     search.</param>
    /// <param name="sort">
    /// True to sort the return array, false
    //     to ignore sorting.
    /// </param>
    /// <returns>The array of director
    //     ies.</returns>
    public string[] GetAllDirectories(string path, bool sort)
    {
    	// Define the return value.
    	string[] strReturnValue = null; 
    	// Define the sizable array.
    	ArrayList arlValues = new ArrayList();
    	// Define the stack.
    	Stack stkDirectories = new Stack();
    try
    {
    	if(path == null || path.Length == 0)
    	{
    		throw new ArgumentNullException("path");
    	}
    	// Validate the path.
    	path = Path.GetFullPath(path);
    	// Place the initial value into the stack.
    	stkDirectories.Push(path);
    	arlValues.Add(path);
    	while(stkDirectories.Count > 0)
    	{
    		string strCurrent = stkDirectories.Pop() as string;
    		string[] strDirs = null;
    		if(strCurrent != null)
    		{
    			try
    			{
    				// Get the listing of directories.
    				strDirs = Directory.GetDirectories(strCurrent);
    			}
    			catch
    			{
    				// Init empty.
    				strDirs = new string[0];
    			}
    			// Iterate the directories.
    			for(int i = 0, j = strDirs.Length; i < j; i++)
    			{
    				string strSubCurrent = strDirs[i];
    				// Place the item into the directory.
    				stkDirectories.Push(strSubCurrent);
    				arlValues.Add(strSubCurrent);
    			}
    		}
    	}//while
    	// Sort the array list.
    	arlValues.Sort();
    	// Define the return value.
    	strReturnValue = new string[arlValues.Count];
    	arlValues.CopyTo(strReturnValue);
    }
    catch(ArgumentNullException aex)
    {
    	throw aex;
    }
    catch(Exception ex)
    {
    	#if DEBUG
    		System.Diagnostics.Debug.WriteLine(new string('-', 50));
    		System.Diagnostics.Debug.WriteLine("Error in: " + ex.TargetSite.Name);
    		System.Diagnostics.Debug.WriteLine(ex.GetType().ToString());
    		System.Diagnostics.Debug.WriteLine(ex.Message);
    		System.Diagnostics.Debug.WriteLine("***" + ex.Source);
    		System.Diagnostics.Debug.WriteLine(new string('-', 50));
    	#endif
    }
    finally
    {
    	// Clear the values array.
    	arlValues.Clear();
    	arlValues = null;
    	// Null stack.
    	stkDirectories = null;
    }
    	// Return the value.
    	return strReturnValue;
    }

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments

 There are no comments on this submission.
 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | .Net Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.