Ejercicio
Lista de imágenes de HTML
Objetivo
Cree un programa para crear un archivo HTML que contenga la lista de imágenes (PNG y JPG) en el directorio actual.
Por ejemplo, en el directorio actual hay imágenes llamadas.
1.png
2.jpg
Código
Imports System
Imports System.IO
Imports System.Collections.Generic
Class ListImagesHTML
Private Shared Sub Main()
CreateHtml(GetImages())
End Sub
Private Shared Sub CreateHtml(ByVal listImages As List)
Try
Dim writer As StreamWriter = New StreamWriter(File.Create("images.html"))
writer.WriteLine("")
writer.WriteLine("")
For Each image As String In listImages
writer.WriteLine("" & image & "")
writer.WriteLine(""");")
Next
writer.WriteLine("")
writer.WriteLine("")
writer.Close()
Catch
Console.WriteLine("Error writing html.")
End Try
End Sub
Private Shared Function GetImages() As List
Dim ListImages As List = New List()
Dim files As String() = Directory.GetFiles(".")
For Each file As String In files
Dim extension As String = Path.GetExtension(file)
Select Case extension
Case ".png", ".jpg", ".jpge"
ListImages.Add(file.Substring(2))
End Select
Next
Return ListImages
End Function
End Class