Rothariger
Regular
- Joined
- Apr 7, 2004
- Messages
- 66
Hello ive make this code, to rename the files with the "Picture Date Taken" property and i leave it a little ugly... someone can help me to clean up..
i use datatables, for the files, so i can use the unique property and the orderby...
but can make it other way... change it at like...
anything just ask...
PD: My english is every day worst..!!!
thanks and salute!!!
i use datatables, for the files, so i can use the unique property and the orderby...
but can make it other way... change it at like...
Visual Basic:
Private Sub BDcmdReemplazar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BDcmdReemplazar.Click
Dim file As String
Dim pattern As String
Dim i As Integer
Dim Fecha As DateTime = DateTime.MinValue
Dim myDr As DataRow
Dim myDataTable As New DataTable
Dim tmpdate As String
If MsgBox("Se van a Renombrar " & System.IO.Directory.GetFiles(BDtxtPath.Text, cmbExt.SelectedValue).Length & " Archivos." & vbCrLf & "Desea Continuar", MsgBoxStyle.YesNo, "Confirmar") = MsgBoxResult.No Then
Exit Sub
End If
myDataTable.Columns.Add(New DataColumn("Numero", GetType(System.Decimal)))
myDataTable.Columns.Add(New DataColumn("Nombre", GetType(System.String)))
myDataTable.Columns(1).Unique = True
myDataTable.Columns.Add(New DataColumn("Path", GetType(System.String)))
myDataTable.Columns.Add(New DataColumn("Fecha", GetType(System.DateTime)))
myDataTable.Columns.Add(New DataColumn("Ext", GetType(System.String)))
For Each file In System.IO.Directory.GetFiles(BDtxtPath.Text, cmbExt.SelectedValue)
Dim myFile As New System.IO.FileInfo(file)
myDr = myDataTable.NewRow
myDr(1) = myFile.Name
myDr(2) = myFile.Directory
tmpdate = Propert(myFile.FullName)
If Trim(tmpdate).CompareTo("0000:00:00 00:00:00") = 0 Then
myDr(3) = Now
Else
myDr(3) = CType((tmpdate.Substring(0, 10)).Replace(":", "-"), Date)
End If
myDr(4) = myFile.Extension
myDataTable.Rows.Add(myDr)
Next
i = 0
For Each myDr In myDataTable.Select("", "Fecha")
If Format(Fecha, "dd-MM-yyyy") <> Format(myDr(3), "dd-MM-yyyy") Then
Fecha = myDr(3)
i = 0
End If
Try
System.IO.File.Move(myDr(2) & "\" & myDr(1), myDr(2) & "\" & Format(myDr(3), "dd-MM-yyyy") & IIf(i = 0, "", " - " & i) & myDr(4))
Catch ex As IOException
MsgBox(ex.Message, MsgBoxStyle.Critical, ex.ToString)
Finally
i += 1
End Try
Next
myDr = Nothing
Fecha = Nothing
End Sub
Private Function Propert(ByVal file As String) As String
Dim img As Image = Image.FromFile(file)
Dim x As String
Try
For Each iPI As Drawing.Imaging.PropertyItem In img.PropertyItems
Select Case iPI.Id
Case "9003" 'Date
If Trim(ASCIIEncoding.ASCII.GetString(iPI.Value)) <> "" Then
Return ASCIIEncoding.ASCII.GetString(iPI.Value)
End If
Case 306 'PropertyTag DateTime
If Trim(ASCIIEncoding.ASCII.GetString(iPI.Value)) <> "" Then
Return ASCIIEncoding.ASCII.GetString(iPI.Value)
End If
Case 36867 'PropertyTag ExifDTOrig
If Trim(ASCIIEncoding.ASCII.GetString(iPI.Value)) <> "" Then
Return ASCIIEncoding.ASCII.GetString(iPI.Value)
End If
Case 36868 'PropertyTagExif DTDigitized
If Trim(ASCIIEncoding.ASCII.GetString(iPI.Value)) <> "" Then
Return ASCIIEncoding.ASCII.GetString(iPI.Value)
End If
End Select
Next
Catch
Finally
img = Nothing
End Try
End Function
anything just ask...
PD: My english is every day worst..!!!
thanks and salute!!!