how to put the progress bar value in a recursive function?

Prabu Spark

Prabu Spark

Aug 19 2014 3:07 AM
Hi sir,
Tell me the steps to put the progress bar value in a recursive function. Consider the following scenarios, i have one folder path "d:\studentinfo" , it contains many subfolders, for that i have to search the pdf files in folders and subfolders of the folder path, i dont know how many files before the process starts. I need to show the progress bar, displaying how much process is completed. I have a recursive function, that search the pdf files in that folder path recursively, my requirement is to display the progress bar in that recursive function.

I shared my recursive function for your reference. Kindly give me the solution to get the progress bar in a recursive function.

//this is the recursive function
public static void getDirsFiles(DirectoryInfo d)
// this.backgroundWorker1.ReportProgress(i);
// System.Threading.Thread.Sleep(500);
//create an array of files using FileInfo object
FileInfo[] files;
//get all files for the current directory
files = d.GetFiles("*.pdf");

//iterate through the directory and print the files
foreach (FileInfo file in files)
//get details of each file using file object
String fileName = file.FullName;
String fileSize = file.Length.ToString();
String fileExtension = file.Extension;
String fileCreated = file.LastWriteTime.ToString();

// HttpContext.Current.Response.Write(fileName + " " + fileSize + " " + fileExtension + " " + fileCreated + "<br><br>");

//get sub-folders for the current directory
DirectoryInfo[] dirs = d.GetDirectories("*.*");

//This is the code that calls
//the getDirsFiles (calls itself recursively)
//This is also the stopping point
//(End Condition) for this recursion function
//as it loops through until
//reaches the child folder and then stops.


foreach (DirectoryInfo dir in dirs)
// HttpContext.Current.Response.Write("--------->> " + dir.Name);


Answers (1)