To maintain or store files on our systems, we may need to create subdirectory within a directory. Now,let's see how to create a sub directory within an existing directory. Perform the following steps to create a subdirectory within an existing directory.
Complete code of How to create sub directory
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication2
{
public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string dirpath = textBox1.Text;
DirectoryInfo dirinfo = new DirectoryInfo(dirpath);
string newsub = textBox2.Text;
dirinfo.CreateSubdirectory(newsub);
label3.Text = "your subdirectory " + newsub + " is created at " + dirpath;
}
}
}
Output using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication2
{
public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string dirpath = textBox1.Text;
DirectoryInfo dirinfo = new DirectoryInfo(dirpath);
string newsub = textBox2.Text;
dirinfo.CreateSubdirectory(newsub);
label3.Text = "your subdirectory " + newsub + " is created at " + dirpath;
}
}
}
Tidak ada komentar:
Posting Komentar