Skip to content

Instantly share code, notes, and snippets.

@JubbaSmail
Created March 13, 2015 12:29
Show Gist options
  • Save JubbaSmail/4917491f28c8d2b7ff61 to your computer and use it in GitHub Desktop.
Save JubbaSmail/4917491f28c8d2b7ff61 to your computer and use it in GitHub Desktop.
using System;
using System.Windows.Forms;
//////////////////////////////
using System.IO;
namespace List_Directory
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
listBox1.Items.Add("..");
try
{
string[] folders = Directory.GetDirectories(comboBox1.Text);
for (int i = 0; i < folders.Length; i++)
{
listBox1.Items.Add(folders[i]);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Clear();
string[] drives = Directory.GetLogicalDrives();
comboBox1.Items.AddRange(drives);
comboBox1.SelectedIndex = 0;
}
private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
int index = listBox1.SelectedIndex;
string path = listBox1.Items[index].ToString();
//MessageBox.Show(path);
listBox1.Items.Clear();
listBox1.Items.Add("..");
try
{
string[] folders = Directory.GetDirectories(path);
for (int i = 0; i < folders.Length; i++)
{
listBox1.Items.Add(folders[i]);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.listBox1 = new System.Windows.Forms.ListBox();
this.button1 = new System.Windows.Forms.Button();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// listBox1
//
this.listBox1.FormattingEnabled = true;
this.listBox1.Location = new System.Drawing.Point(12, 40);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(345, 342);
this.listBox1.TabIndex = 0;
this.listBox1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.listBox1_MouseDoubleClick);
//
// button1
//
this.button1.Location = new System.Drawing.Point(278, 13);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 2;
this.button1.Text = "List";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// comboBox1
//
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(13, 13);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(259, 21);
this.comboBox1.TabIndex = 3;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(371, 406);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.listBox1);
this.Name = "Form1";
this.Text = "Directory Manager";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.ComboBox comboBox1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment