using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Files_Folder;
using System.IO;
using System.Data;
namespace WriteListFileFolder
{
class Program
{
static void Main(string[] args)
{
DataTable DtTblList;
DtTblList = new DataTable();
DtTblList.Columns.Add("SrNo", typeof(int));
DtTblList.Columns.Add("EntryType", typeof(int));
DtTblList.Columns.Add("Path", typeof(string));
GetFileFolders(ref DtTblList, "D:\\GSDIntegration");
DtTblList.WriteXml("D\\XmlFile.xml");
}
static void GetFileFolders(ref DataTable DtTblList, string FolderPath)
{
string[] ListDirectory = Directory.GetDirectories( FolderPath);
if (ListDirectory.Length > 0)
{
for (int n = 0; n < ListDirectory.Length; n++)
{
DataRow _D = DtTblList.NewRow();
_D["SrNo"] = DtTblList.Rows.Count + 1; _D["EntryType"] = 1;
_D["Path"] = ListDirectory[n]; DtTblList.Rows.Add(_D);
GetFileFolders(ref DtTblList, ListDirectory[n]);
}
}
else
{
string[] ListOfFiles = Directory.GetFiles(FolderPath);
for (int i = 0; i < ListOfFiles.Length; i++)
{
DataRow _D = DtTblList.NewRow();
_D["SrNo"] = DtTblList.Rows.Count + 1; _D["EntryType"] = 2;
_D["Path"] = ListOfFiles[i]; DtTblList.Rows.Add(_D);
}
}
}
}
}