XK8ER
asked on
vb.net - progress bar
Hello there,
I am using this code to create directories based on the date that the picture was taken. it looks for all of the images in a directory and then it moves them.
when I select a dir that contains about 3k pictures it gets frozen for about 3 minutes saying "not responding" and then all the pictures are sorted out correctly..
I would like to prevent that and have a progress bar showing the percentage done.. how can I do that exactly?
I am using this code to create directories based on the date that the picture was taken. it looks for all of the images in a directory and then it moves them.
when I select a dir that contains about 3k pictures it gets frozen for about 3 minutes saying "not responding" and then all the pictures are sorted out correctly..
I would like to prevent that and have a progress bar showing the percentage done.. how can I do that exactly?
Imports System.IO
Imports System.Text
Imports System.Drawing.Imaging
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
ProcessFiles(FolderBrowserDialog1.SelectedPath, "*.jpg")
End If
End Sub
Private Sub ProcessFiles(ByVal Folder As String, ByVal Pattern As String)
Dim di As New DirectoryInfo(Folder)
For Each fi As FileInfo In di.GetFiles(Pattern, SearchOption.AllDirectories)
Dim values() As String = FindDateTaken(fi.FullName).Split(":")
If values.Length >= 2 Then
values(2) = values(2).Split(" ")(0)
Try
Dim dt As New DateTime(values(0), values(1), values(2))
Dim SubDi As New DirectoryInfo(Path.Combine(di.FullName, dt.Year))
If Not SubDi.Exists() Then
SubDi.Create()
End If
SubDi = New DirectoryInfo(Path.Combine(SubDi.FullName, dt.Month.ToString("00")))
If Not SubDi.Exists() Then
SubDi.Create()
End If
SubDi = New DirectoryInfo(Path.Combine(SubDi.FullName, dt.Day.ToString("00")))
If Not SubDi.Exists() Then
SubDi.Create()
End If
Dim NewFileName As String = Path.Combine(SubDi.FullName, fi.Name)
fi.MoveTo(NewFileName)
Catch ex As Exception
End Try
End If
Next
End Sub
Private Function FindDateTaken(ByVal strPicture As String) As String
Const DATE_TAKEN As Integer = &H9003
Dim dateTaken As String = ""
Using img As Image = Image.FromFile(strPicture)
If img.PropertyIdList.Contains(DATE_TAKEN) Then
Dim pitem As PropertyItem = img.GetPropertyItem(DATE_TAKEN)
dateTaken = Encoding.UTF8.GetString(pitem.Value, 0, pitem.Value.Length)
End If
End Using
Return dateTaken
End Function
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER