C#C
C#2y ago
Komitet

I want to find file when the file it's found I want to say where is the file path

I created this code and nothing:
           List<string> fileNameToFind = new List<string>()
{
    "d3d10.dll",
    "d3d10(1).dll"
};

            string informacoesEncontradas = "";
            string username = Environment.UserName;
            string allPath = Path.GetFullPath(@"C:\\");

            try
            {
                if (Directory.Exists(allPath))
                {
                    informacoesEncontradas += $"Files found at {allPath}\n";

                    string[] foundFilesAll = Directory.GetFiles(allPath, "*", SearchOption.AllDirectories);

                    if (foundFilesAll.Length > 0)
                    {
                        foreach (string filePath in foundFilesAll)
                        {
                            foreach (string fileName in fileNameToFind)
                            {
                                if (Path.GetFileName(filePath) == fileName)
                                {
                                    informacoesEncontradas += filePath + "\n";
                                }
                            }
                        }
                        informacoesEncontradas = "EXP -> " + informacoesEncontradas;
                    }
                }
            }
            catch (Exception ex)
            {
                // Handle the exception
            }
Was this page helpful?