Ejemplo n.º 1
0
        private void CreateListing(string OpenedDirectory)
        {
            int total = 0, folders = 0, files = 0;
            DirectoryInfo di;
            var tree = new List<ExtFileSystemInfo>();
            //if "\\", show "my computer" - enumerate all disks
            if (OpenedDirectory == @"\\" || OpenedDirectory == "Мой компьютер")
            {
                DirectoryListing.Clear();
                string[] disks = Environment.GetLogicalDrives();
                foreach (string disk in disks) tree.Add(new ExtFileSystemInfo(disk));
                total = disks.Length;
            }
            else
            {
                di = new DirectoryInfo(OpenedDirectory);

                var infos = di.GetFileSystemInfos();

                for (int i = 0; i < infos.Count(); i++)
                {
                    var data = infos.ElementAt(i);
                    ExtFileSystemInfo result = null;

                    //if not show hidden
                    if (!ShowHiddenObjects)
                    {
                        //if it isn't hidden, add it
                        if ((data.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
                            result = new ExtFileSystemInfo(data.FullName);
                    }
                    else
                        result = new ExtFileSystemInfo(data.FullName);
                    if (result == null) continue;
                    if (result.IsDirectory) folders++;
                    if (result.IsFile) files++;

                    tree.Add(result);
                }

                DirectoryListing.Clear();
                //if local disk, set parent to my computer
                if (OpenedDirectory.Length == 3)
                    DirectoryListing.Add(new ExtFileSystemInfo(@"Мой компьютер") { IsSpecial = true });
                else
                {
                    if (di.Parent != null)
                        DirectoryListing.Add(new ExtFileSystemInfo(di.Parent.FullName) { IsSpecial = true });
                }
                total = infos.Length;
            }
            foreach (var e in tree.OrderByDescending(i => i.IsDirectory))
                DirectoryListing.Add(e);

            InformationLine = string.Format("Всего: {0} (Папок: {1}, Файлов: {2})", folders + files, folders, files);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates new filename for already existing file or folder.
        /// </summary>
        /// <param name="targetPath">Path, where new file or folder will be located</param>
        /// <param name="item">ExtFileSystemInfo object which describes file or folder</param>
        /// <param name="name">Current file or folder name</param>
        /// <returns>Full path with filename, which doesn't exist on disk</returns>
        public static string CreateNewFileName(string targetPath, ExtFileSystemInfo item, string name)
        {
            string targetName = Path.Combine(targetPath, name);
            int i = 2;
            Func<string, bool> caller;
            if (item.IsFile)
            {
                caller = new Func<string, bool>(File.Exists);
            }
            else
                caller = new Func<string, bool>(Directory.Exists);

            while (caller(targetName))
                targetName = Path.Combine(targetPath, name + string.Format("({0})", i++));

            return targetName;
        }