Replace file in DirInternal?

JonPM

Well-Known Member
Licensed User
Longtime User
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

:sign0163:
 

margret

Well-Known Member
Licensed User
Longtime User
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
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
First msgbox = null
second = Replaced File

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?
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
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?
 
Last edited:
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
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?

It is changed on the dev machine
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
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'm sure you're right, 99.9% of the time its user error :p

Here is the code I'm using to view the file in the app:
B4X:
Reader.Initialize(File.OpenInput(File.DirInternal,"File1.txt"))
   txt = Reader.ReadAll
   lblDose.Text = txt
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
Is this a one item text file? What is in the File1.txt? If it is just one word/item, try opening it with the line below and see what it returns:

B4X:
Msgbox(File.ReadString(File.DirInternal, "File1.txt"), "")

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.
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
In the files tab it its File1.txt but in windows explorer its file1.txt. Tried changing the case but still didn't work. will keep trying...

Sent from my DROIDX
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
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...
 
Upvote 0
Top