Is it possible to transfer images included in the apk in another folder

alan1968

Active Member
Licensed User
Longtime User
Is it possible to transfer images included in the apk in another folder [Solved]

Re hello
in my project, I create two folder with the "File.MakeDir" this folder are used by the user to stored images
Currently the folder is empty after installing the program
I'd like to put some image that the user can use the program without having to find their own images
I had thought to put the image in "File.DirAssets" and copy the installation in a user folder but I doubted it "File.Copy (File.DirAssets, MyFile, folder_pics, MyFile)" does not work

what solution you advise me?
 
Last edited:

Mahares

Expert
Licensed User
Longtime User
Would this work for you?
B4X:
Dim MyFolder, MyFile as string
MyFolder= "/Alan1968"
MyFile ="Sunset.png"
File.Copy(File.DirAssets,MyFile,File.DirRootExternal & MyFolder,MyFile)  'copy to a folder in SD card named: Alan1968
 
Upvote 0

alan1968

Active Member
Licensed User
Longtime User
thx! but my code is same
B4X:
...
folder_pics=File.DirRootExternal & "/PROJET/PICS"
..
'copy picture button to folder pics
Dim MyList As List
Dim MyFile As String
Dim YuFile As String
Dim i As Short
MyList.Initialize 
MyList=File.ListFiles(File.DirAssets)
For i=0 To MyList.Size-1
MyFile=MyList.Get(i) 
if Mid(MyFile,1,2)="x_" Then 'x_picture.png copy only
YuFile=mid(MyFile,3,MyFile.Length-2) 'picture.png
File.Copy(File.DirAssets,MyFile,folder_pics,YuFile)
end if
Next
..
Sub Mid(Text As String, Start As Int, Length As Int) As String
Return Text.SubString2(Start-1,Start+Length-1)
End Sub
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Why do you doubt your code will not work. Did you try it and get errors. What kind of error are you getting. I must be missing something!
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
If you are like some programmers that want the code to be as short as possible, you can do away with the Mid subroutine. Here is the complete equivalent code:

B4X:
Dim folder_pics As String
folder_pics=File.DirRootExternal & "/PROJET/PICS"
..
'copy picture button to folder pics
Dim MyList As List
Dim MyFile As String
Dim YuFile As String
Dim i As Short
MyList.Initialize 
MyList=File.ListFiles(File.DirAssets)
For i=0 To MyList.Size-1
  MyFile=MyList.Get(i) 
  If MyFile.StartsWith("x_") Then
     YuFile=MyFile.SubString(2)  ''x_picture.png becomes 'picture.png
     File.Copy(File.DirAssets,MyFile,folder_pics,YuFile)
  End If
Next
Merci
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…