File System

Rusty

Well-Known Member
Licensed User
Longtime User
Update file timestamp

I notice when I FTP a file to my Android the timestamp gets updated to the time it is downloaded. I would like to maintain the timestamp from the original file on the FTP site. Is there a File.??? function that would allow me to reset the timestamp on the downloaded file to make it match the timestamp on the FTP site? (like File.SetTimeStamp(...))
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I actually wrote some code to do it using Reflector. However there seems to be a bug in Android which prevents it from working: Issue 18624 - android - setLastModified() always fails on Xoom unless running as root - Android - An Open Handset Alliance Project - Google Project Hosting

You can try it if you like. It may work with internal files. It should return true if the operation was successful:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Log(DateTime.Date(File.LastModified(File.DirRootExternal, "1.zip")))
    SetLastModified(File.DirRootExternal, "1.zip", DateTime.DateParse("02/23/2007"))
    Log(DateTime.Date(File.LastModified(File.DirRootExternal, "1.zip")))
End Sub

Sub SetLastModified(Dir As String, FileName As String, Ticks As Long)
    Dim r As Reflector
    r.Target = r.CreateObject2("java.io.File", Array As String(Dir, FileName), _
        Array As String("java.lang.String", "java.lang.String"))
    Log(r.RunMethod4("setLastModified", Array As Object(Ticks), Array As String("java.lang.long")))
End Sub
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Erel,
I am not experiencing any "bug" with your code. It seems to work perfectly. Maybe it is the version of Android OS...
I'm running Eclair, kernal 2.6.29 #125
Thanks
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Yes, I have created a folder on File.DirRootExternal, I download via FTP then use your code to reset the date/time. Works perfectly.
 
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
SetLastModified is fine for Changing Modified Date in Device when Downloading from Server Via FTP,but My Problem is When I Upload from Device to Server Via FTP the Server Files Date has created newly.Pls advise how to Change Server Files Date like when downloading from server to Device.
 
Upvote 0

tkristensen

Member
Licensed User
Longtime User
I'm having some difficulties with the SetLastModified routine listed above. I'm using Android 4.0.3 and the code and parameters past in are listed below:

code:
Sub SetLastModified(Dir As String, FileName As String, Ticks As Long)
Dim R As Reflector
R.Target = R.CreateObject2("java.io.File", Array As String(Dir, FileName), Array As String("java.lang.String", "java.lang.String"))
Log(R.RunMethod4("setLastModified", Array As Object(Ticks), Array As String("java.lang.long")))
End Sub

Parameters:
dir = /mnt/sdcard/survey/commoninfo/download
filename = talkingsurvey.apk
ticks=1367502642587

The log message always returns false and the file date is not updated. The datetime.date(ticks) does return the proper date.

Any idea of what I'm doing wrong?

Thanks in advance...

Tom
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [ code ] [ /code ] tags (without spaces) when posting code.

This is probably related to this Android bug: https://code.google.com/p/android/issues/detail?id=18624

The solution proposed there is to open the file with RandomAccessFile read one byte and write it back. This will set the modified time to the current time.
 
Upvote 0
Top