In an upcoming market update, I am trying to replace a file that users already have stored in their DirInternal folder from original install. However this code doesn't seem to update the existing file:
B4X:
Sub FileReplace
Dim File1 As String
File1 = Map1.Get("File1Status")
If File1 <> "updated" Then
File.Delete(File.DirInternal,"File1.txt")
File.Copy(File.DirAssets,"File1.txt",File.DirInternal,"File1.txt")
Map1.Put("File1Status","updated")
File.WriteMap(File.DirInternal,"Map.dat",Map1)
End If
End Sub
File1 may not contain what you think it does, but I don't have the rest of your code. Run this modified version and see if it writes the proper data to the log file:
B4X:
Sub FileReplace
Dim File1 As String
File1 = Map1.Get("File1Status")
log(File1) 'or use MsgBox(File1 ,"")
If File1 <> "updated" Then
File.Delete(File.DirInternal,"File1.txt")
File.Copy(File.DirAssets,"File1.txt",File.DirInternal,"File1.txt")
log("Replaced File...") 'or Msgbox("Replaced File...", "")
Map1.Put("File1Status","updated")
File.WriteMap(File.DirInternal,"Map.dat",Map1)
End If
End Sub
Yet the content of the file did not change when I accessed it within the app. If I modify a file in the Files folder it should update each time I compile the app, correct?
Yes, if you update a file in the Files directory on the development machine and re-compile your app, it should include any changes you have made. Have you looked inside the File1.txt file to confirm your changes are there on the development machine?
How is File1.txt getting into your apps directory the first time you install your app? Are you copying it to File.DirInternal in some other code? Do you have other code that accesses this file? What does that code look like?
Yes, if you update a file in the Files directory on the development machine and re-compile your app, it should include any changes you have made. Have you looked inside the File1.txt file to confirm your changes are there on the development machine?
I think we should look at the code in your app that accesses this file. You said it did not change in your app, maybe it is looking somewhere else other than: File.DirInternal.
I think we should look at the code in your app that accesses this file. You said it did not change in your app, maybe it is looking somewhere else other than: File.DirInternal.
Also, android is case sensitive and I think wants lower case names. In your code you keep showing "File1.txt". I would change it on your dev machine to "file1.txt" and change your code as well and see if it works.
I'm about to give up. I've tried every possibility I can think of and still can't get it to overwrite the old file. I think I need to take a few days off, lol...
Remove the file from the files tab, where it says File1.txt. You don't need it in the files tab anyway, all files in the assets directory will be included in the build by default. If you want it in the files tab, remove it and add it back and see if it adds it back as file1.txt. Then try your code again.