file.copy error

squaremation

Active Member
Licensed User
Longtime User
:signOops:double post by accident, left computer while posting and got logged out:signOops:]

Trying to store some extra data outside the db, and I keep getting this error 'no such file or directory exists' from this code



B4X:
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
         If File.Exists(File.DirRootExternal, "User.txt") = True Then
      
                 File.Copy(File.DirInternal, "User.txt", File.DirRootExternal, "User.txt") 'keep getting error 
'on this line have checked the /File and it is included and same spelling and capital
         File.Copy(File.DirInternal, "Level.txt", File.DirRootExternal, "Leveltxt")
         File.Copy(File.DirInternal, "Score.txt", File.DirRootExternal, "Score.txt")
         File.Copy(File.DirInternal, "Cash.txt", File.DirRootExternal, "Cash.txt")
         read
         Else
      
         File.WriteString (File.DirRootExternal, "User.txt","")
         File.WriteString (File.DirRootExternal, "Leveltxt", "")
         File.WriteString (File.DirRootExternal, "Score.txt","")
         File.WriteString (File.DirRootExternal, "Cash.txt","")
   
         'read
      End If
   End If
 
Last edited:

NJDude

Expert
Licensed User
Longtime User
Change this line:

From:
B4X:
If File.Exists(File.DirRootExternal, "User.txt") = True Then
To:
B4X:
If File.Exists(File.DirRootExternal, "User.txt") = False Then

If you are running the app for the very first time the file doesn't exist in DirRootExternal, that's why you have to ask for FALSE (doesn't exist)

Also, change these lines:

From:
B4X:
File.Copy(File.DirInternal, "Level.txt", File.DirRootExternal, "Leveltxt")
File.Copy(File.DirInternal, "Score.txt", File.DirRootExternal, "Score.txt")
File.Copy(File.DirInternal, "Cash.txt", File.DirRootExternal, "Cash.txt")
To:
B4X:
File.Copy(File.DirAssets, "Level.txt", File.DirRootExternal, "Leveltxt")
File.Copy(File.DirAssets, "Score.txt", File.DirRootExternal, "Score.txt")
File.Copy(File.DirAssets, "Cash.txt", File.DirRootExternal, "Cash.txt")

Again, those files do not exist when you run the app for the very first time, you have to copy them from File.DirAssets.

If you need more info about files/directories read THIS
 
Upvote 0
Top