Hey,
if you download a file with Google Chrome for example and you have you've already downloaded this one time, then a number will appear next to it. This is now easy possible with this peace of code.
Output: mytestname(1).jpg
Greetings
if you download a file with Google Chrome for example and you have you've already downloaded this one time, then a number will appear next to it. This is now easy possible with this peace of code.
B4X:
checkfilename(File.DirDefaultExternal,"mytestname.jpg",0,"mytestname.jpg")
B4X:
Sub checkfilename(dir As String,filename As String, lastint As Int,lastfilename As String) As String
Dim filename2(2) As String = Regex.Split("\.",filename)
Dim filename3 As String = filename
If File.Exists(dir,lastfilename) = True Then
lastint = lastint +1
lastfilename = filename2(0) & "(" & lastint & ")" & "." & filename2(1)
checkfilename(dir,filename3,lastint,lastfilename)
Else
Return lastfilename
End If
End Sub
Output: mytestname(1).jpg
Greetings