I have a method that will iterate through a folder and all of its subfolders and get a list of the file paths. However, I could only figure out how to create it and add the files to a public List, but not how to return the list. Here's the method:
public List<String> files = new List<String>();  private void DirSearch(string sDir)     {         try         {             foreach (string f in Directory.GetFiles(sDir))             {                 files.Add(f);             }             foreach (string d in Directory.GetDirectories(sDir))             {                 DirSearch(d);             }         }         catch (System.Exception excpt)         {             MessageBox.Show(excpt.Message);         }     }   So, i just call DirSearch() at some point in my code and it 'fills' the list with the paths, but I want to be able to use it multiple times to create different lists with different directories, etc.
PHP using scandir() to find folders in a directory The scandir function is an inbuilt function that returns an array of files and directories of a specific directory. It lists the files and directories present inside the path specified by the user.
Press and hold the SHIFT key and then right-click the folder that contains the files you need listed. Click Open command window here on the new menu. A new window with white text on a black background should appear. o To the left of the blinking cursor you will see the folder path you selected in the previous step.
You can use Directory.GetFiles to replace your method.
 Directory.GetFiles(dirPath, "*", SearchOption.AllDirectories) 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With