Hello,
I am trying to create a new sub directory in an all ready created Folder. What happens is that when files are transferred from one directory to another it creates a sub directory everytime and places the files into it. I have got the part working for the creation of a folder but everytime the files go into the main folder it gets placed into the same sub folder and doesn't create a new one for the files to be placed into. Any help???
Thanks.
private void butSort1_Click(object sender, EventArgs e)
{
DirectoryInfo di = new DirectoryInfo(@"C:\new1");
FileInfo[] fiArr = di.GetFiles("*.txt");
int iCtr = 0;
int iloop = 0;
try
{
foreach (FileInfo fri in fiArr)
{
//create a new directory
DirectoryInfo dir = new DirectoryInfo(@"C:\\new2");
//If that directory doesn't exsit create a new directory
if (dir.Exists == false)
{
dir.Create();
}
DirectoryInfo dis = dir.CreateSubdirectory("newnew" + "(" + iloop + ")");
if (dis.Exists == true)
{
dis.Create();
}
else
{
//move files from dir to the new sub directory
MessageBox.Show(fri.FullName.ToString(), "File Manager", MessageBoxButtons.OK);
fri.MoveTo(@"C:\new2\newnew\" + "1(" + iCtr + ").txt");
//loop round to add the file name
iCtr++;
iloop++;
//Refresh the label attributes
RefreshDirSize1();
RefreshDirSize2();
RefreshDirSize3();
RefreshDirSize4();
}
}
}
catch (Exception b)
{
lblErrors.Text = (b.ToString());
}
}