Android Question How to copy file without changing last modified date?


Well-Known Member
Licensed User
When you use File.Copy (or File.Copy2) it changes the last modified date of target file. I found this code posted by Erel to set the date manually.
Dim f As JavaObject

f.InitializeNewInstance("", Array(File.Combine(dir, filename))
f.RunMethod("setLastModified", Array(File.LastModified(original file)))
While it works, the file I am trying to modify is on external SD card and there is no permission to modify a file on external SD directly. It can be done only using android.intent.action.OPEN_DOCUMENT_TREE intent that returns URI and not physical path. And copying a file to external SD card itself is a pain but that has been solved here.

So the question is how to preserve (or manually set) the last modified date of a file when the file is accessed only via URI (like content:// It is somehow possible because when you copy a file using third party file managers, it preserves the date.


Staff member
Licensed User
I don't see any API that allows you to change the last modified value of DocumentFile.