You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create an index.html file with a list of Links with PDF file names
usingSystem;usingSystem.IO;usingSystem.Text;classProgram{staticvoidMain(){conststringdirPath="./data";conststringoutputPath="./index.html";// Check if the directory existsif(!Directory.Exists(dirPath)){Console.WriteLine($"Directory '{dirPath}' does not exist.");return;}// Get pdf filesvarpdfFiles=Directory.GetFiles(dirPath,"*.pdf");// Sort the file names in alphabetical orderArray.Sort(pdfFiles,StringComparer.InvariantCulture);varsb=newStringBuilder();sb.AppendLine("<html><title> PDF files</title>");sb.AppendLine("<body>");sb.AppendLine("<h1>List of ebooks</h1>");sb.AppendLine("<ul>");// Create a list item for each pdf fileforeach(varpdfFileinpdfFiles){varfileName=Path.GetFileName(pdfFile);varlinkText=Path.GetFileNameWithoutExtension(fileName).Replace("_"," ");// Replace underscores with spacessb.AppendLine($"<li><a href=\"{fileName}\">{linkText}</a></li>");}sb.AppendLine("</ul>");sb.AppendLine("</body>");sb.AppendLine("</html>");// Write to output fileFile.WriteAllText(outputPath,sb.ToString());Console.WriteLine("Index.html has been created.");}}