Combines two path strings.

   
 

#region License and Copyright
/* -------------------------------------------------------------------------
 * Dotnet Commons IO
 *
 *
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by 
 * the Free Software Foundation; either version 2.1 of the License, or 
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 
 * for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public License 
 * along with this library; if not, write to the 
 * 
 * Free Software Foundation, Inc., 
 * 59 Temple Place, 
 * Suite 330, 
 * Boston, 
 * MA 02111-1307 
 * USA 
 * 
 * -------------------------------------------------------------------------
 */
#endregion

using System;
using System.Collections;
using System.Globalization;
using System.IO;

namespace Dotnet.Commons.IO
{
    class MainClass
    {
        /// ---------------------------------------------------------------
        /// <summary>
        /// Combines two path strings.
        /// </summary>
        /// <param name="path1">The first path.</param>
        /// <param name="path2">The second path.</param>
        /// <returns>
        /// A string containing the combined paths. If one of the specified 
        /// paths is a zero-length string, this method returns the other path. 
        /// If <paramref name="path2" /> contains an absolute path, this method 
        /// returns <paramref name="path2" />.
        /// </returns>
        /// <remarks>
        ///   <para>
        ///   On Unix, processing is delegated to <see cref="Path.Combine(string, string)" />.
        ///   </para>
        ///   <para>
        ///   On Windows, this method normalized the paths to avoid running into
        ///   the 260 character limit of a path and converts forward slashes in 
        ///   both <paramref name="path1" /> and <paramref name="path2" /> to 
        ///   the platform&#039;s directory separator character.
        ///   </para>
        /// 
        ///  Courtesy of NAnt project.
        /// </remarks>
        /// ---------------------------------------------------------------
        public static string CombinePaths(string path1, string path2)
        {


            if (path1 == null)
            {
                throw new ArgumentNullException("path1");
            }
            if (path2 == null)
            {
                throw new ArgumentNullException("path2");
            }

            if (Path.IsPathRooted(path2))
            {
                return path2;
            }

            char separatorChar = Path.DirectorySeparatorChar;
            char[] splitChars = new char[] { &#039;/&#039;, separatorChar };

            // Now we split the Path by the Path Separator
            String[] path2Parts = path2.Split(splitChars);

            ArrayList arList = new ArrayList();

            // for each Item in the path that differs from ".." we just add it 
            // to the ArrayList, but skip empty parts
            for (int iCount = 0; iCount < path2Parts.Length; iCount++)
            {
                string currentPart = path2Parts&#91;iCount&#93;;

                // skip empty parts or single dot parts
                if (currentPart.Length == 0 || currentPart == ".")
                {
                    continue;
                }

                // if we get a ".." Try to remove the last item added (as if 
                // going up in the Directory Structure)
                if (currentPart == "..")
                {
                    if (arList.Count > 0 &amp;&amp; ((string)arList[arList.Count - 1] != ".."))
                    {
                        arList.RemoveAt(arList.Count - 1);
                    }
                    else
                    {
                        arList.Add(currentPart);
                    }
                }
                else
                {
                    arList.Add(currentPart);
                }
            }

            bool trailingSeparator = (path1.Length > 0 &amp;&amp; path1.IndexOfAny(splitChars, path1.Length - 1) != -1);

            // if the first path ends in directory seperator character, then 
            // we need to omit that trailing seperator when we split the path
            string[] path1Parts;
            if (trailingSeparator)
            {
                path1Parts = path1.Substring(0, path1.Length - 1).Split(splitChars);
            }
            else
            {
                path1Parts = path1.Split(splitChars);
            }

            int counter = path1Parts.Length;

            // if the second path starts with parts to move up the directory tree, 
            // then remove corresponding parts in the first path
            //
            // eg. path1 = d:whateveryouwant	odo 
            //     path2 = ../../test
            //     
            //     ->
            //
            //     path1 = d:whateveryouwant
            //     path2 = test
            ArrayList arList2 = (ArrayList)arList.Clone();
            for (int i = 0; i < arList2.Count; i++)
            {
                // never discard first part of path1
                if ((string)arList2&#91;i&#93; != ".." || counter < 2)
                {
                    break;
                }

                // skip part of current directory
                counter--;

                arList.RemoveAt(0);
            }

            string separatorString = separatorChar.ToString(CultureInfo.InvariantCulture);

            // if path1 only has one remaining part, and the original path had
            // a trailing separator character or the remaining path had multiple
            // parts (which were discarded by a relative path in path2), then
            // add separator to remaining part
            if (counter == 1 &amp;&amp; (trailingSeparator || path1Parts.Length > 1))
            {
                path1Parts[0] += separatorString;
            }

            string combinedPath = Path.Combine(string.Join(separatorString, path1Parts,
                0, counter), string.Join(separatorString, (String[])arList.ToArray(typeof(String))));

            // if path2 ends in directory separator character, then make sure
            // combined path has trailing directory separator character
            if (path2.EndsWith("/") || path2.EndsWith(separatorString))
            {
                combinedPath += Path.DirectorySeparatorChar;
            }

            return combinedPath;
        }
    }
}

   
     


Split the path into array of string

   
 

#region License and Copyright
/* -------------------------------------------------------------------------
 * Dotnet Commons IO
 *
 *
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by 
 * the Free Software Foundation; either version 2.1 of the License, or 
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 
 * for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public License 
 * along with this library; if not, write to the 
 * 
 * Free Software Foundation, Inc., 
 * 59 Temple Place, 
 * Suite 330, 
 * Boston, 
 * MA 02111-1307 
 * USA 
 * 
 * -------------------------------------------------------------------------
 */
#endregion

using System;
using System.Collections;
using System.Globalization;
using System.IO;

namespace Dotnet.Commons.IO
{
  
  ///  
  /// <summary>  
  /// This class provides basic facilities for manipulating files and file paths.
    /// 
    /// <h3>File-related methods</h3>
    /// There are methods to 
    /// <list type="bullet">
    ///     <item>copy a file to another file,</item>
    ///     <item>compare the content of 2 files,</item>
    ///     <item>delete files using the wildcard character,</item>
    ///     <item>etc</item>
    /// </list>
  /// </summary>
  ///     
  public sealed class FileUtils
  {

        /// ---------------------------------------------------------------
        /// <summary>
        /// Determine if a path provided is the path of a file
        /// </summary>
        /// <param name="path"></param>
        /// <returns>true if path is a valid file, false otherwise</returns>
        /// ---------------------------------------------------------------
        public static bool IsFile(string path)
        {
            return File.Exists(path);
        }



        /// ---------------------------------------------------------------
        /// <summary>
        /// Determine if a path is the path of a directory.
        /// </summary>
        /// <param name="path"></param>
        /// <returns>true if path is a valid directory, false otherwise</returns>
        /// ---------------------------------------------------------------
        public static bool IsDirectory(string path)
        {
            return Directory.Exists(path);
        }


        /// ---------------------------------------------------------------
        /// <summary>
        /// Split the path into array of string
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        /// ---------------------------------------------------------------
        public static String[] SplitPath(string path)
        {
            String[] pathSeparators = new String[] { "" };
            return path.Split(pathSeparators, StringSplitOptions.RemoveEmptyEntries);
        }

  }
}

   
     


Combines two path strings.

   
 

#region License and Copyright
/* -------------------------------------------------------------------------
 * Dotnet Commons IO
 *
 *
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by 
 * the Free Software Foundation; either version 2.1 of the License, or 
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 
 * for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public License 
 * along with this library; if not, write to the 
 * 
 * Free Software Foundation, Inc., 
 * 59 Temple Place, 
 * Suite 330, 
 * Boston, 
 * MA 02111-1307 
 * USA 
 * 
 * -------------------------------------------------------------------------
 */
#endregion

using System;
using System.Collections;
using System.Globalization;
using System.IO;

namespace Dotnet.Commons.IO
{
    class MainClass
    {
        /// ---------------------------------------------------------------
        /// <summary>
        /// Combines two path strings.
        /// </summary>
        /// <param name="path1">The first path.</param>
        /// <param name="path2">The second path.</param>
        /// <returns>
        /// A string containing the combined paths. If one of the specified 
        /// paths is a zero-length string, this method returns the other path. 
        /// If <paramref name="path2" /> contains an absolute path, this method 
        /// returns <paramref name="path2" />.
        /// </returns>
        /// <remarks>
        ///   <para>
        ///   On Unix, processing is delegated to <see cref="Path.Combine(string, string)" />.
        ///   </para>
        ///   <para>
        ///   On Windows, this method normalized the paths to avoid running into
        ///   the 260 character limit of a path and converts forward slashes in 
        ///   both <paramref name="path1" /> and <paramref name="path2" /> to 
        ///   the platform&#039;s directory separator character.
        ///   </para>
        /// 
        ///  Courtesy of NAnt project.
        /// </remarks>
        /// ---------------------------------------------------------------
        public static string CombinePaths(string path1, string path2)
        {


            if (path1 == null)
            {
                throw new ArgumentNullException("path1");
            }
            if (path2 == null)
            {
                throw new ArgumentNullException("path2");
            }

            if (Path.IsPathRooted(path2))
            {
                return path2;
            }

            char separatorChar = Path.DirectorySeparatorChar;
            char[] splitChars = new char[] { &#039;/&#039;, separatorChar };

            // Now we split the Path by the Path Separator
            String[] path2Parts = path2.Split(splitChars);

            ArrayList arList = new ArrayList();

            // for each Item in the path that differs from ".." we just add it 
            // to the ArrayList, but skip empty parts
            for (int iCount = 0; iCount < path2Parts.Length; iCount++)
            {
                string currentPart = path2Parts&#91;iCount&#93;;

                // skip empty parts or single dot parts
                if (currentPart.Length == 0 || currentPart == ".")
                {
                    continue;
                }

                // if we get a ".." Try to remove the last item added (as if 
                // going up in the Directory Structure)
                if (currentPart == "..")
                {
                    if (arList.Count > 0 &amp;&amp; ((string)arList[arList.Count - 1] != ".."))
                    {
                        arList.RemoveAt(arList.Count - 1);
                    }
                    else
                    {
                        arList.Add(currentPart);
                    }
                }
                else
                {
                    arList.Add(currentPart);
                }
            }

            bool trailingSeparator = (path1.Length > 0 &amp;&amp; path1.IndexOfAny(splitChars, path1.Length - 1) != -1);

            // if the first path ends in directory seperator character, then 
            // we need to omit that trailing seperator when we split the path
            string[] path1Parts;
            if (trailingSeparator)
            {
                path1Parts = path1.Substring(0, path1.Length - 1).Split(splitChars);
            }
            else
            {
                path1Parts = path1.Split(splitChars);
            }

            int counter = path1Parts.Length;

            // if the second path starts with parts to move up the directory tree, 
            // then remove corresponding parts in the first path
            //
            // eg. path1 = d:whateveryouwant	odo 
            //     path2 = ../../test
            //     
            //     ->
            //
            //     path1 = d:whateveryouwant
            //     path2 = test
            ArrayList arList2 = (ArrayList)arList.Clone();
            for (int i = 0; i < arList2.Count; i++)
            {
                // never discard first part of path1
                if ((string)arList2&#91;i&#93; != ".." || counter < 2)
                {
                    break;
                }

                // skip part of current directory
                counter--;

                arList.RemoveAt(0);
            }

            string separatorString = separatorChar.ToString(CultureInfo.InvariantCulture);

            // if path1 only has one remaining part, and the original path had
            // a trailing separator character or the remaining path had multiple
            // parts (which were discarded by a relative path in path2), then
            // add separator to remaining part
            if (counter == 1 &amp;&amp; (trailingSeparator || path1Parts.Length > 1))
            {
                path1Parts[0] += separatorString;
            }

            string combinedPath = Path.Combine(string.Join(separatorString, path1Parts,
                0, counter), string.Join(separatorString, (String[])arList.ToArray(typeof(String))));

            // if path2 ends in directory separator character, then make sure
            // combined path has trailing directory separator character
            if (path2.EndsWith("/") || path2.EndsWith(separatorString))
            {
                combinedPath += Path.DirectorySeparatorChar;
            }

            return combinedPath;
        }
    }
}

   
     


Make Absolute Path

   
 

#region License and Copyright
/* -------------------------------------------------------------------------
 * Dotnet Commons IO
 *
 *
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by 
 * the Free Software Foundation; either version 2.1 of the License, or 
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 
 * for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public License 
 * along with this library; if not, write to the 
 * 
 * Free Software Foundation, Inc., 
 * 59 Temple Place, 
 * Suite 330, 
 * Boston, 
 * MA 02111-1307 
 * USA 
 * 
 * -------------------------------------------------------------------------
 */
#endregion

using System;
using System.Collections;
using System.IO;
using System.Reflection;
using System.Web;

namespace Dotnet.Commons.IO
{
  /// <summary>
  ///  Path handling utility methods that are not available in System.IO.Path
  /// </summary>
    /// <remarks>Authors: Gonzalo Paniagua Javier (gonzalo@ximian.com)</remarks>
  public sealed class PathUtils
  {
    static string appbase;
    static char [] separators;


    private PathUtils()
    {    
    }

        
    /// <summary>
    /// Static Constructor
    /// </summary>    
    static PathUtils ()
    {      
      Assembly entry = Assembly.GetEntryAssembly ();
      appbase = Path.GetDirectoryName (entry.Location);
      
      if (Path.DirectorySeparatorChar != Path.AltDirectorySeparatorChar)
        separators = new char [] {Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar};
      else
        separators = new char [] {Path.DirectorySeparatorChar};
    }

    /// <summary>
    /// 
    /// </summary>    
    /// <param name="abspath"></param>
    /// <returns></returns>
    /// <remarks>Authors: Gonzalo Paniagua Javier (gonzalo@ximian.com)</remarks>
    public static string MakeAbsolute (string abspath)
    {
      
      string [] parts = abspath.Split (separators);
      ArrayList valid = new ArrayList ();

      int len = parts.Length;
      bool hasDots = false;

      for (int i = 0; i < len; i++) 
      {
        if (parts &#91;i&#93; == ".") 
        {
          hasDots = true;
          continue;
        }

        if (parts &#91;i&#93; == "..") 
        {
          hasDots = true;
          if (valid.Count > 0)
            valid.RemoveAt (valid.Count - 1);
          continue;
        }

        valid.Add (parts [i]);
      }

      if (!hasDots)
        return abspath;

      parts = (String []) valid.ToArray (typeof (string));
      string result = String.Join (new String (Path.DirectorySeparatorChar, 1), parts);
      if (!Path.IsPathRooted (result))
        return Path.DirectorySeparatorChar + result;

      return result;
    }
    }
}

   
     


Get Relative Path

   
 
#region License and Copyright
/* -------------------------------------------------------------------------
 * Dotnet Commons IO
 *
 *
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by 
 * the Free Software Foundation; either version 2.1 of the License, or 
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 
 * for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public License 
 * along with this library; if not, write to the 
 * 
 * Free Software Foundation, Inc., 
 * 59 Temple Place, 
 * Suite 330, 
 * Boston, 
 * MA 02111-1307 
 * USA 
 * 
 * -------------------------------------------------------------------------
 */
#endregion

using System;
using System.Collections;
using System.Globalization;
using System.IO;

namespace Dotnet.Commons.IO
{
  
  ///  
  /// <summary>  
  /// This class provides basic facilities for manipulating files and file paths.
    /// 
    /// <h3>File-related methods</h3>
    /// There are methods to 
    /// <list type="bullet">
    ///     <item>copy a file to another file,</item>
    ///     <item>compare the content of 2 files,</item>
    ///     <item>delete files using the wildcard character,</item>
    ///     <item>etc</item>
    /// </list>
  /// </summary>
  ///     
  public sealed class FileUtils
  {
        /// ---------------------------------------------------------------
        /// <summary>
        /// Get Relative Path
        /// </summary>
        /// <param name="rootPath"></param>
        /// <param name="fullPath"></param>
        /// <returns></returns>
        /// <remarks>Based on Turtle.Lib.Utilities.FileUtils</remarks>
        /// ---------------------------------------------------------------
        public static string GetRelativePath(string rootPath, string fullPath)
        {
            if (String.IsNullOrEmpty(rootPath) || String.IsNullOrEmpty(fullPath))
            {
                return null;
            }
            else if (fullPath.Equals(rootPath))
            {
                return string.Empty;
            }
            else if (fullPath.Contains(rootPath + ""))
            {
                return fullPath.Substring(rootPath.Length + 1);
            }
            else
            {
                return null;
            }
        }
    }
}

   
     


Gets a list of files

   
 
/*
Copyright (c) 2010 <a href="http://www.gutgames.com">James Craig</a>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/

#region Usings
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;

#endregion

namespace Utilities
{
    /// <summary>
    /// Utility class for managing files
    /// </summary>
    public static class FileManager
    {
        /// <summary>
        /// Determines if a directory exists
        /// </summary>
        /// <param name="DirectoryPath">Path of the directory</param>
        /// <returns>true if it exists, false otherwise</returns>
        public static bool DirectoryExists(string DirectoryPath)
        {
            try
            {
                return Directory.Exists(DirectoryPath);
            }
            catch (Exception a)
            {
                throw a;
            }
        }
        /// <summary>
        /// Gets a list of files
        /// </summary>
        /// <param name="DirectoryPath">Directory to check for files</param>
        /// <param name="Recursive">Determines if this is a recursive look at all directories under this one</param>
        /// <returns>a list of files</returns>
        public static List<FileInfo> FileList(string DirectoryPath,bool Recursive)
        {
            try
            {
                if (!Recursive)
                {
                    return FileList(DirectoryPath);
                }
                List<FileInfo> Files = new List<FileInfo>();
                if (DirectoryExists(DirectoryPath))
                {
                    DirectoryInfo Directory = new DirectoryInfo(DirectoryPath);
                    FileInfo[] SubFiles = Directory.GetFiles();
                    foreach (FileInfo SubFile in SubFiles)
                    {
                        Files.Add(SubFile);
                    }
                    DirectoryInfo[] SubDirectories = Directory.GetDirectories();
                    foreach (DirectoryInfo SubDirectory in SubDirectories)
                    {
                        List<FileInfo> TempFiles = FileList(SubDirectory.FullName, Recursive);
                        foreach (FileInfo File in TempFiles)
                        {
                            Files.Add(File);
                        }
                    }
                }
                return Files;
            }
            catch (Exception a)
            {
                throw a;
            }
        }        
        /// <summary>
        /// Gets a list of files
        /// </summary>
        /// <param name="DirectoryPath">Directory to check for files</param>
        /// <returns>a list of files</returns>
        public static List<FileInfo> FileList(string DirectoryPath)
        {
            try
            {
                List<FileInfo> Files = new List<FileInfo>();
                if (DirectoryExists(DirectoryPath))
                {
                    DirectoryInfo Directory = new DirectoryInfo(DirectoryPath);
                    FileInfo[] SubFiles = Directory.GetFiles();
                    foreach (FileInfo SubFile in SubFiles)
                    {
                        Files.Add(SubFile);
                    }
                }
                return Files;
            }
            catch (Exception a)
            {
                throw a;
            }
        }

    }
}

   
     


Directory listing

   
 
/*
Copyright (c) 2010 <a href="http://www.gutgames.com">James Craig</a>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/

#region Usings
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;

#endregion

namespace Utilities
{
    /// <summary>
    /// Utility class for managing files
    /// </summary>
    public static class FileManager
    {
        /// <summary>
        /// Determines if a directory exists
        /// </summary>
        /// <param name="DirectoryPath">Path of the directory</param>
        /// <returns>true if it exists, false otherwise</returns>
        public static bool DirectoryExists(string DirectoryPath)
        {
            try
            {
                return Directory.Exists(DirectoryPath);
            }
            catch (Exception a)
            {
                throw a;
            }
        }
        /// <summary>
        /// Directory listing
        /// </summary>
        /// <param name="DirectoryPath">Path to get the directories in</param>
        /// <returns>List of directories</returns>
        public static List<DirectoryInfo> DirectoryList(string DirectoryPath)
        {
            try
            {
                List<DirectoryInfo> Directories = new List<DirectoryInfo>();
                if (DirectoryExists(DirectoryPath))
                {
                    DirectoryInfo Directory = new DirectoryInfo(DirectoryPath);
                    DirectoryInfo[] SubDirectories = Directory.GetDirectories();
                    foreach (DirectoryInfo SubDirectory in SubDirectories)
                    {
                        Directories.Add(SubDirectory);
                    }
                }
                return Directories;
            }
            catch (Exception a)
            {
                throw a;
            }
        }


    }
}