Esempio n. 1
0
        /// <summary>
        /// Gets all items in a direcory and all it's subdirectories.
        /// </summary>
        /// <param name="path">A path to a directory.</param>
        /// <returns>A tree of items in a directory.</returns>
        public static ExtendedObservableCollection <TreeItem> GetItems(string path)
        {
            var items = new ExtendedObservableCollection <TreeItem>();

            try
            {
                var dirInfo = new DirectoryInfo(path);

                foreach (var directory in dirInfo.GetDirectories())
                {
                    var item = new DirectoryItem
                    {
                        Name  = directory.Name,
                        Path  = directory.FullName,
                        Items = GetItems(directory.FullName)
                    };

                    items.Add(item);
                }

                foreach (var file in dirInfo.GetFiles())
                {
                    var item = new FileItem
                    {
                        Name = file.Name,
                        Path = file.FullName
                    };

                    items.Add(item);
                }
            }
            catch (Exception ex)
            {
                var item = new FileItem
                {
                    Name = ex.Message,
                    Path = ex.ToString()
                };

                items.Add(item);
            }

            return(items);
        }
Esempio n. 2
0
 public DirectoryItem()
 {
     Items = new ExtendedObservableCollection <TreeItem>();
 }