Splits a path into all parts of its directories, e.g. "maps\\sub\\the" becomes {"maps\\sub\\the","maps\\sub","maps"} - CSharp File IO

CSharp examples for File IO:Directory

Description

Splits a path into all parts of its directories, e.g. "maps\\sub\\the" becomes {"maps\\sub\\the","maps\\sub","maps"}

Demo Code


using System.Text;
using System.Linq;
using System.IO;// w ww. ja  v a2 s.  c o  m
using System.Collections.Generic;
using System.Collections;
using System;

public class Main{
        /// <summary>
        /// Splits a path into all parts of its directories,
        /// e.g. "maps\\sub\\kekse" becomes
        /// {"maps\\sub\\kekse","maps\\sub","maps"}
        /// </summary>
        static public string[] SplitDirectories(string path)
        {
            ArrayList localList = new ArrayList();
            localList.Add(path);
            do
            {
                path = CutOneFolderOff(path);
                if (path.Length > 0)
                    localList.Add(path);
            } while (path.Length > 0);

            return (string[])localList.ToArray(typeof(string));
        } // SplitDirectories(path)
}

Related Tutorials