Sub Globals
Dim yearstr,monthstr,daystr,hourstr,minstr,secstr As String
Dim datestr,timestr As String
Dim str As String
Dim seperator As String
Dim path1,root As String
Dim lastnum,date_time_tick As Long
Dim picturelist,picturelist2 As List
Dim picturenum As Int
Dim checkbtn As Button
Dim newpic As Boolean
End Sub
Sub Activity_Create(FirstTime As Boolean)
checkbtn.Initialize("checkbtn")
Activity.AddView(checkbtn,30%x,30%y,40%x,20%y)
checkbtn.Text="Check Picture"
picturelist.Initialize
picturelist2.Initialize
root=File.DirRootExternal
path1 = root & "/DCIM/Camera"
get_picture_list
lastnum=0
For n = 0 To picturelist.Size-1
str = picturelist.Get(n)
yearstr=str.SubString2(4,8)
monthstr=str.SubString2(8,10)
daystr=str.SubString2(10,12)
hourstr=str.SubString2(13,15)
minstr=str.SubString2(15,17)
secstr=str.SubString2(17,19)
'Log(yearstr&" "&monthstr&" "&daystr&" "&hourstr&" "&minstr&" "&secstr)
datestr=monthstr&"/"&daystr&"/"&yearstr
timestr=hourstr&":"&minstr&":"&secstr
date_time_tick=DateTime.DateTimeParse(datestr,timestr)
If date_time_tick>lastnum Then
lastnum=date_time_tick
picturenum=n
End If
Next
End Sub
Sub get_picture_list
Dim filelist As List
filelist.Initialize
filelist = File.ListFiles(path1)
Dim file1,file2 As String
picturelist.Clear
For n = 0 To filelist.Size-1
file1 = filelist.Get(n)
file2=file1.ToUpperCase
If (file2.EndsWith(".PNG")) Or (file2.EndsWith(".BMP")) Or (file2.EndsWith(".JPG")) Or (file2.EndsWith(".JPEG")) Then
picturelist.Add(file1)
End If
Next
End Sub
Sub checkbtn_Click
check_new_picture
End Sub
Sub check_new_picture
Dim filelist As List
filelist.Initialize
filelist = File.ListFiles(path1)
Dim file1,file2,lastpicture As String
picturelist2.Clear
For n = 0 To filelist.Size-1
file1 = filelist.Get(n)
file2=file1.ToUpperCase
If (file2.EndsWith(".PNG")) Or (file2.EndsWith(".BMP")) Or (file2.EndsWith(".JPG")) Or (file2.EndsWith(".JPEG")) Then
picturelist2.Add(file1)
End If
Next
For n = 0 To picturelist2.Size-1
str = picturelist2.Get(n)
yearstr=str.SubString2(4,8)
monthstr=str.SubString2(8,10)
daystr=str.SubString2(10,12)
hourstr=str.SubString2(13,15)
minstr=str.SubString2(15,17)
secstr=str.SubString2(17,19)
'Log(yearstr&" "&monthstr&" "&daystr&" "&hourstr&" "&minstr&" "&secstr)
datestr=monthstr&seperator&daystr&seperator&yearstr
timestr=hourstr&":"&minstr&":"&secstr
'Log(datestr&" "×tr)
date_time_tick=DateTime.DateTimeParse(datestr,timestr)
'Log(date_time_tick)
If date_time_tick>lastnum Then
lastnum=date_time_tick
picturenum=n
End If
Next
lastpicture=picturelist2.Get(picturenum)
newpic=True
For n=0 To picturelist.Size-1
If lastpicture=picturelist.Get(n) Then
newpic=False
End If
Next
If newpic Then
Log("Last picture = "&lastpicture)
renamefile(lastpicture,"test.jpg")
End If
End Sub
Sub renamefile(oldfile As String,newfile As String)
File.Copy(path1,oldfile,path1,newfile)
File.Delete(path1,oldfile)
End Sub