本文介绍了如何将进度条值放在c#windows应用程序的递归函数中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,

告诉我将进度条值放在递归函数中的步骤。考虑以下场景,我有一个文件夹路径d:\studentinfo,它包含许多子文件夹,因为我必须在文件夹路径的文件夹和子文件夹中搜索pdf文件,我不知道在进程之前有多少文件开始。我需要显示进度条,显示完成了多少进程。我有一个递归函数,递归地搜索该文件夹路径中的pdf文件,我的要求是在该递归函数中显示进度条。



我分享了我的递归函数供你参考。请给我解决方案,以递归功能获得进度条。





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)
            {
                i++;
                //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.

            //HttpContext.Current.Response.Write("<br>");

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

        }

推荐答案

string[] files = Directory.GetFiles(@"D:\Temp\", "*.pdf", SearchOption.AllDirectories);

它将返回整个分支中的所有PDF文件,作为具有完整文件路径的字符串。

然后你知道在开始处理它们之前有多少。 ..

And it will return you all the PDF files in the whole branch, as strings with the complete file path.
Then you know how many there are before you even start processing them...



这篇关于如何将进度条值放在c#windows应用程序的递归函数中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 13:06