using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SaveflodersPathGrid
{
public partial class Form1 : Form
{
private DirectoryInfo directory;
private FileInfo fileName;
private List<Folders> objFolders = new List<Folders>();
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SaveflodersPathGrid
{
public partial class Form1 : Form
{
private DirectoryInfo directory;
private FileInfo fileName;
private List<Folders> objFolders = new List<Folders>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DirSearch("C:\\IMS VIDEOs LATEST FOLDER WISE", objFolders);
#region
//DirectoryInfo dinfo = new DirectoryInfo(@"C:\IMS VIDEOs LATEST FOLDER WISE"); // Populates field with all Sub Folders
//DirectoryInfo[] maindirectory = dinfo.GetDirectories();
//DirectoryInfo[] subdir = new DirectoryInfo[] { };
//DirectoryInfo[] supersubdir = new DirectoryInfo[] { };
//string filename = string.Empty;
//FileInfo[] filnames = new FileInfo[] { };
//List<Folders> lstFolders = new List<Folders>();
//foreach (DirectoryInfo directory in maindirectory)
//{
// subdir = directory.GetDirectories();
// if (subdir.Count() > 0)
// {
// foreach (DirectoryInfo supersub in subdir)
// {
// if (supersub.GetDirectories().Count() > 0)
// {
// foreach (DirectoryInfo subsubfolder in supersub.GetDirectories())
// {
// filnames = subsubfolder.GetFiles();
// foreach (FileInfo f in filnames)
// {
// lstFolders.Add(new Folders { MainFolder = directory.Name, SubFolder = supersub.Name, SuperSubFolder = subsubfolder.Name, FileName = f.Name });
// }
// }
// }
// else
// {
// filnames = supersub.GetFiles();
// foreach (FileInfo f in filnames)
// {
// lstFolders.Add(new Folders { MainFolder = directory.Name, SubFolder = supersub.Name, SuperSubFolder = "", FileName = f.Name });
// }
// }
// }
// }
// else
// {
// filnames = directory.GetFiles();
// foreach (FileInfo f in filnames)
// {
// lstFolders.Add(new Folders { MainFolder = directory.Name, SubFolder = "", SuperSubFolder = "", FileName = f.Name });
// }
// }
//}
//FolderDataGrid.DataSource = lstString;
#endregion
FolderDataGrid.DataSource = objFolders;
}
//public void DirSearch(DirectoryInfo directory, FileInfo fileName)
//{
// directory = new DirectoryInfo(@"C:\IMS VIDEOs LATEST FOLDER WISE");
// List<Folders> lstFolders = new List<Folders>();
// foreach (DirectoryInfo maindir in directory.GetDirectories())
// {
// foreach (DirectoryInfo subdir in maindir.GetDirectories())
// {
// foreach (DirectoryInfo supersubdir in subdir.GetDirectories())
// {
// foreach (FileInfo filename in supersubdir.GetFiles())
// {
// lstFolders.Add(new Folders { MainFolder = maindir.Name, SubFolder = subdir.Name, SuperSubFolder = supersubdir.Name, FileName = filename.Name });
// }
// }
// }
// }
//}
//private List<Folders> DirSearch(string sDir, List<Folders> objVideo)
//{
// try
// {
// foreach (string d in Directory.GetDirectories(sDir))
// {
// if (Directory.GetFiles(d).Count() > 0)
// {
// foreach (string f in Directory.GetFiles(d))
// {
// objVideo.Add(new Folders()
// {
// MainFolder = d,
// SubFolder = "",
// SuperSubFolder = "",
// FileName = f
// });
// }
// }
// else
// {
// foreach (string subdir in Directory.GetDirectories(sDir))
// {
// if (Directory.GetFiles(sDir).Count() > 0)
// {
// foreach (string f in Directory.GetFiles(subdir))
// {
// objVideo.Add(new Folders()
// {
// MainFolder = d,
// SubFolder = subdir,
// SuperSubFolder = "",
// FileName = f
// });
// }
// }
// else
// {
// foreach (string supersubdir in Directory.GetDirectories(sDir))
// {
// foreach (string f in Directory.GetFiles(supersubdir))
// {
// objVideo.Add(new Folders()
// {
// MainFolder = d,
// SubFolder = subdir,
// SuperSubFolder = supersubdir,
// FileName = f
// });
// }
// }
// }
// }
// }
// DirSearch(d, objVideo);
// // DirSearch(directory, fileName);
// }
// }
// catch (System.Exception excpt)
// {
// throw excpt;
// }
// return objVideo;
//}
private List<Folders> DirSearch(string sDir, List<Folders> objFolders)
{
try
{
foreach (string d in Directory.GetDirectories(sDir))
{
if (Directory.GetDirectories(d).Count() > 0)
{
foreach (string subdir in Directory.GetDirectories(d))
{
string Mdir = d;
char[] Mdir2 = new char[] { '\\' };
string[] strSplitArr = Mdir.Split(Mdir2);
if (Directory.GetDirectories(subdir).Count() > 0)
{
foreach (string supersubdir in Directory.GetDirectories(subdir))
{
string Sdir = subdir;
char[] Sdir2 = new char[] { '\\' };
string[] SdirSplitArr = Sdir.Split(Sdir2);
string Supdir = supersubdir;
char[] Supdir2 = new char[] { '\\' };
string[] SupdirSplitArr = Supdir.Split(Supdir2);
foreach (string f in Directory.GetFiles(supersubdir))
{
string fdir = f;
char[] fdir2 = new char[] { '\\' };
string[] fSplitArr = fdir.Split(fdir2);
if (fSplitArr[5] == "Bank")
{
objFolders.Add(new Folders()
{
MainFolder = strSplitArr[2],
SubFolder = SdirSplitArr[3],
SuperSubFolder = SupdirSplitArr[4] + SupdirSplitArr[5],
FileName = fSplitArr[5]
});
}
else
{
objFolders.Add(new Folders()
{
MainFolder = strSplitArr[2],
SubFolder = SdirSplitArr[3],
SuperSubFolder = SupdirSplitArr[4],
FileName = fSplitArr[5]
});
}
}
}
}
else
{
foreach (string f in Directory.GetFiles(subdir))
{
string Sdir = subdir;
char[] Sdir2 = new char[] { '\\' };
string[] SdirSplitArr = Sdir.Split(Sdir2);
string fdir = f;
char[] fdir2 = new char[] { '\\' };
string[] fSplitArr = fdir.Split(fdir2);
objFolders.Add(new Folders()
{
MainFolder = strSplitArr[2],
SubFolder = SdirSplitArr[3],
SuperSubFolder = "",
FileName = fSplitArr[4]
});
}
}
}
#region
//if (Directory.GetDirectories(d).Count() > 0)
//{
// foreach (string supersubdir in Directory.GetDirectories(subdir))
// {
// //if (Directory.GetFiles(subdir).Count() > 0)
// //{
// foreach (string f in Directory.GetFiles(subdir))
// {
// objVideo.Add(new Folders()
// {
// MainFolder = d,
// SubFolder = subdir,
// SuperSubFolder = supersubdir,
// FileName = f
// });
// }
// //}
// //else
// //{
// // foreach (string f in Directory.GetFiles(subdir))
// // {
// // objVideo.Add(new Folders()
// // {
// // MainFolder = d,
// // SubFolder = subdir,
// // SuperSubFolder = "",
// // FileName = f
// // });
// // }
// //}
// }
//}
//else
//{
// foreach (string f in Directory.GetFiles(d))
// {
// objVideo.Add(new Folders()
// {
// MainFolder = d,
// SubFolder = "",
// SuperSubFolder = "",
// FileName = f
// });
// }
//}
#endregion
}
else
{
foreach (string f in Directory.GetFiles(d))
{
string Mdir = d;
char[] Mdir2 = new char[] { '\\' };
string[] strSplitArr = Mdir.Split(Mdir2);
string fdir = f;
char[] fdir2 = new char[] { '\\' };
string[] fSplitArr = fdir.Split(fdir2);
objFolders.Add(new Folders()
{
MainFolder = strSplitArr[2],
SubFolder = "",
SuperSubFolder = "",
FileName = fSplitArr[3]
});
}
}
DirSearch(d, objFolders);
}
}
catch (System.Exception excpt)
{
throw excpt;
}
return objFolders;
}
}
}
No comments:
Post a Comment
Hello all, if you have any doubt feel free comment