1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
| '-----------------------------------------------------------------
' Code fonctionnel tel que conçu sous VBA Access 2007
' et importé sous VB2008 Express avec erreurs
'-----------------------------------------------------------------
Public Class PicturesRenamer
Private Sub ButtonSource_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSource.Click
If FolderBrowserDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
TextBoxSource.Text = FolderBrowserDialog.SelectedPath & "\"
End If
End Sub
Private Sub ButtonDestination_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDestination.Click
If FolderBrowserDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then
TextBoxDestination.Text = FolderBrowserDialog.SelectedPath & "\"
End If
End Sub
Private Sub RenamePictures(ByVal SourceFolder As String, ByVal DestinationFolder As String, ByVal PictureName As String)
Dim clGdip As New clGdiPlus 'Classe de récupération de données EXIF venant de VBA ne fonctionnant pas ici
Dim FileName As String
Dim FileDate As String
Dim NumFiles As Integer
Dim Files() As String
Dim Position As Integer
Dim OldPictureName As String
Dim NewPictureName As String
Dim i As Integer
If Len(PictureName) = 0 Then
MsgBox("Please enter a standard Windows name for your pictures.", vbOKOnly + vbInformation, "PictureRename")
Exit Sub
End If
If Len(SourceFolder) = 0 Then
MsgBox("Please select a directory which contains your pictures.", vbOKOnly + vbInformation, "PictureRename")
Exit Sub
End If
If Len(DestinationFolder) = 0 Then
MsgBox("Please select a destination directory for your renamed pictures.", vbOKOnly + vbInformation, "PictureRename")
Exit Sub
End If
If SourceFolder = DestinationFolder Then
MsgBox("Please select differents directories.", vbOKOnly + vbInformation, "PictureRename")
Exit Sub
End If
clGdip = New clGdiPlus 'Type 'clGdiPlus' non défini. --> Normal
FileName = Dir(SourceFolder)
Do While Len(FileName) > 0
If FileName <> "." And FileName <> ".." Then
NumFiles = NumFiles + 1
ReDim Preserve Files(1 To NumFiles) 'Les limites inférieures du tableau ne peuvent être que '0'.
clGdip.OpenFile(SourceFolder & FileName)
FileDate = Format(clGdip.GetExifData(TagDateTimeOriginal), "yyyymmddhhnnss") 'Le nom 'TagDateTimeOriginal' n'est pas déclaré. --> Normal
Files(NumFiles) = FileDate & "%" & FileName
End If
FileName = Dir()
Loop
clGdip.CloseFile()
QuickSort(Files, 1, NumFiles)
For i = 1 To NumFiles
Position = InStr(1, Files(i), "%", vbTextCompare)
FileName = Right(Files(i), (Len(Files(i)) - Position)) 'Public ReadOnly Property Right() As Integer' n'a aucun paramètre et son type de retour ne peut pas être indexé.
OldPictureName = SourceFolder & FileName
NewPictureName = DestinationFolder & PictureName & " (" & Format(i, "###000") & ").jpg"
Name OldPictureName As NewPictureName 'Un accès à la propriété doit assigner la propriété ou utiliser sa valeur.
Next i
MsgBox("Operation finished.")
End Sub
Private Sub QuickSort(ByVal List() As String, ByVal Min As Long, ByVal Max As Long)
Dim Median As String
Dim Hight As Long
Dim Low As Long
Dim i As Long
If Min >= Max Then Exit Sub
i = Int((Max - Min + 1) * Rnd() + Min)
Median = List(i)
List(i) = List(Min)
Low = Min
Hight = Max
Do
Do While List(Hight) >= Median
Hight = Hight - 1
If Hight <= Low Then Exit Do
Loop
If Hight <= Low Then
List(Low) = Median
Exit Do
End If
List(Low) = List(Hight)
Low = Low + 1
Do While List(Low) < Median
Low = Low + 1
If Low >= Hight Then Exit Do
Loop
If Low >= Hight Then
Low = Hight
List(Hight) = Median
Exit Do
End If
List(Hight) = List(Low)
Loop
QuickSort(List, Min, Low - 1)
QuickSort(List, Low + 1, Max)
End Sub
Private Sub ButtonRename_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonRename.Click
Call RenamePictures(TextBoxSource.Text, TextBoxDestination.Text, TextBoxName.Text)
End Sub
End Class |
Partager