To get list of drives and create a directory in selected drive
In this we will do coding to get all the drives in system during the form load. And then create the directory in a particular drive by selecting it from combobox.
First create a combobox button which shows list of drives. Also create a radiobutton , a label , a textbox and a button .
Initial during the page load label, textbox and button visibility is false.And when the radiobutton is clicked their visibity is true.
GetLogicalDrives is a method od directory class used to get list of drives.
following is the code which is to be written in form1.cs page:
//To get all logical drives GetLogicalDrives method of Directory class is //used
private void Form1_Load(object sender, EventArgs e)
{
String[] drive;
drive = Directory.GetLogicalDrives();
for (int i = 0; i < drive.Length; i++)
{
cmbdrive.Items.Add(drive[i].ToString());
}
}
//It will create a directory and if it already exist a message is displayed //that directly already exists.
private void btnCrDir_Click(object sender, EventArgs e)
{
string s = txtDirname.Text;
if (Directory.Exists(s))
{
MessageBox.Show("Directory Already Exists");
}
else
{
Directory.CreateDirectory(s);
MessageBox.Show("Directory Created");
}
}
private void rbdcdir_CheckedChanged(object sender, EventArgs e)
{
label1.Visible = true;
txtDirname.Visible = true;
btnCrDir.Visible = true;
}
nice example simple but explains clearly how to get all the drives.
thanks a lot..