Home > Mobile >  How to run the first file existing with the selected format?
How to run the first file existing with the selected format?

Time:10-15

I would like to read an existing html file from a folder and run it. I know, I could run given a specific file, the problem is that my program will delete the previous HTML file and generate anew with a different file name.

All I know is that the process to start running the program is:

Process.Start("firefox.exe", $@"C:\Users\domin\..\*.html");

This is just my imagination of how it would be done, but that is not the way. How can I do that?

CodePudding user response:

You could use FileSystemWatcher in folder path and add the required filters and events to it. And write your logic in the event.

CodePudding user response:

var ext = new List<string> { "html" };
var myFiles = Directory
   .EnumerateFiles(pathResult, "*.*", SearchOption.AllDirectories)
   .Where(s => ext.Contains(Path.GetExtension(s).TrimStart('.').ToLowerInvariant()));

var filehtml = myFiles.First();

var p = new Process();
p.StartInfo = new ProcessStartInfo($@"{filehtml}")
{
   UseShellExecute = true
};
p.Start();

This was solved my problem

  • Related