How do I pass the name of the files that were found inside the selected folder?
So far I've only been able to get him to get the file's path and move on to DataGridView
and now I want to make him pass the name too.
Here's the code part for FolderBrowserDialog
.
private void btnDiretorio_Click(object sender, EventArgs e)
{
this.grvShowFile.Rows.Clear();
folderBrowserDialog.RootFolder = Environment.SpecialFolder.DesktopDirectory;
folderBrowserDialog.SelectedPath = openFileDialog.InitialDirectory;
folderBrowserDialog.ShowNewFolderButton = true;
openFileDialog.Filter = "Form (*.frm)|*.frm|" + "All files (*.*)|*.*";
DialogResult result = folderBrowserDialog.ShowDialog();
if (result == DialogResult.OK)
{
List<string> selectedPath = listaArquivos(folderBrowserDialog.SelectedPath);
foreach (string s in selectedPath)
{
grvShowFile.Rows.Add(s);
}
}
}
public List<string> listaArquivos(string dir)
{
List<string> lstDirs = Directory.GetDirectories(dir).ToList();
List<string> lstFiles = Directory.GetFiles(dir).ToList();
List<string> lstFilesAux = new List<string>();
foreach(string ldir in lstDirs)
lstFilesAux = listaArquivos(ldir);
lstFiles.AddRange(lstFilesAux);
return lstFiles;
}
And if you can also tell me how I can get it to just find the files that are in the filter, I would appreciate it.