Ejemplo n.º 1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            DriveInfo[] Drives = DriveInfo.GetDrives();
            string[] directories;
            ICatalog Current;
            TreeNode node;
            for (int i = 0; i < Drives.Length; i++)
            {
                treeView1.Nodes.Add(Drives[i].Name);
                if (Drives[i].DriveType == DriveType.Removable || Drives[i].DriveType == DriveType.CDRom)
                    continue;
                FolderObj fo = new FolderObj();
                Current = (ICatalog)fo;
                Current.Initialize(Drives[i].Name);
                Current.ReloadFiles();
                int n = Current.GetDirectoriesCount();
                if (n == 0)
                    continue;
                directories = new string[n];
                for (int j = 0; j < n; j++)
                    directories[j] = Current.GetDirectoryName(j);

                foreach (var directory in directories)
                {
                    node = new TreeNode(directory);
                    node.ImageIndex = 0;
                    treeView1.Nodes[i].Nodes.Add(node);
                }
            }
            for(int i=0; i < treeView1.Nodes.Count; i++)
            {
                DriveInfo di = new DriveInfo(treeView1.Nodes[i].Text);
                if (di.DriveType == DriveType.Fixed)
                {
                    treeView1.SelectedNode = treeView1.Nodes[i];
                    return;
                }
            }
        }