For example, in the current directory there are images called.
1.png
2.jpg
The result should be:
<html>
<body>
<p>1.png</p>
<img src="1.png" alt="1.png" />
<p>2.jpg</p>
<img src="2.jpg" alt="2.jpg" />
</body>
</html>
using System;
using System.IO;
using System.Collections.Generic;
class ListImagesHTML
{
static void Main()
{
CreateHtml(GetImages());
}
static void CreateHtml(List listImages)
{
try
{
StreamWriter writer = new StreamWriter(File.Create("images.html"));
writer.WriteLine("");
writer.WriteLine("");
foreach (string image in listImages)
{
writer.WriteLine(image);
writer.WriteLine("img alt='" + image + "' src='" + image + "'");
}
writer.WriteLine("");
writer.WriteLine("");
writer.Close();
}
catch
{
Console.WriteLine("Error writing html.");
}
}
static List GetImages()
{
List ListImages = new List();
string[] files = Directory.GetFiles(".");
foreach (string file in files)
{
string extension = Path.GetExtension(file);
switch (extension)
{
case ".png":
case ".jpg":
case ".jpge":
ListImages.Add(file.Substring(2));
break;
}
}
return ListImages;
}
}