G
Guest
I need to write script in c# that will scan directories for files and insert
the files and directory names in the database.. I've have two tables tblDir
and tblDocs.
Example:
-Directory1
a_file1
a_file2
Directory1_1
b_file1
b_file2
-Directory2
a_file1
a_file2
Directory2_1
b_file1
b_file2
root_file1
root_file2
I want to record the file and directory list as shown below:
tblDir
---------------------------------
id | TopID | DirName |
---------------------------------
1 0 Directory1
2 1 Directory1_1
3 0 Directory2
4 2 Directory2_1
tblDocs
-----------------------------------
id | DirID | FileName |
-----------------------------------
1 0 root_file1
2 0 root_file2
3 1 a_File1
4 1 a_File2
5 2 b_File1
6 2 b_File1
7 3 a_File1
8 3 a_File2
9 4 b_File1
10 4 b_File1
Here is my codes.. i seem to be getting the folder records in a wrong
place.. please help.
int FolderID = 0;
foreach (string f in Directory.GetFiles(sDir))
{
file = f.Substring(f.LastIndexOf("\\")+1);
if(!doc.DocExist(DepID,FolderID,file))
{
doc.AddDoc(DepID,FolderID,file);
}
}
foreach (string d in Directory.GetDirectories(sDir))
{
folder = d.Substring(d.LastIndexOf("\\")+1);
if(!doc.FolderExist(DepID,FolderID,folder))
{
FolderID = doc.AddFolder(DepID,FolderID,folder);
}
foreach (string f in Directory.GetFiles(d))
{
folder = d.Substring(d.LastIndexOf("\\")+1);
file2 = f.Substring(f.LastIndexOf("\\")+1);
FolderID = doc.GetFolderID(folder);
if(!doc.DocExist(DepID,FolderID,file2))
{
DocID = doc.AddDoc(DepID,FolderID,file2);
}
}
DirSearch(d,DepID);
}
the files and directory names in the database.. I've have two tables tblDir
and tblDocs.
Example:
-Directory1
a_file1
a_file2
Directory1_1
b_file1
b_file2
-Directory2
a_file1
a_file2
Directory2_1
b_file1
b_file2
root_file1
root_file2
I want to record the file and directory list as shown below:
tblDir
---------------------------------
id | TopID | DirName |
---------------------------------
1 0 Directory1
2 1 Directory1_1
3 0 Directory2
4 2 Directory2_1
tblDocs
-----------------------------------
id | DirID | FileName |
-----------------------------------
1 0 root_file1
2 0 root_file2
3 1 a_File1
4 1 a_File2
5 2 b_File1
6 2 b_File1
7 3 a_File1
8 3 a_File2
9 4 b_File1
10 4 b_File1
Here is my codes.. i seem to be getting the folder records in a wrong
place.. please help.
int FolderID = 0;
foreach (string f in Directory.GetFiles(sDir))
{
file = f.Substring(f.LastIndexOf("\\")+1);
if(!doc.DocExist(DepID,FolderID,file))
{
doc.AddDoc(DepID,FolderID,file);
}
}
foreach (string d in Directory.GetDirectories(sDir))
{
folder = d.Substring(d.LastIndexOf("\\")+1);
if(!doc.FolderExist(DepID,FolderID,folder))
{
FolderID = doc.AddFolder(DepID,FolderID,folder);
}
foreach (string f in Directory.GetFiles(d))
{
folder = d.Substring(d.LastIndexOf("\\")+1);
file2 = f.Substring(f.LastIndexOf("\\")+1);
FolderID = doc.GetFolderID(folder);
if(!doc.DocExist(DepID,FolderID,file2))
{
DocID = doc.AddDoc(DepID,FolderID,file2);
}
}
DirSearch(d,DepID);
}