One-Time Copy Files from Assets to Defaultexternal

Bill Norris

Active Member
Licensed User
Longtime User
As I have developed this app, I have ended up with a lot of files in dir.assets that I want to move to dir.defaultexternal. What would be the easiest code to do this -- one time shot? Basically, copy every file from dir.assets into dir.defaultexternal, then I can go into dir.defaultexternal using file manager on the device and delete those files that actually should stay in dir.assets -- bal files, etc., and I would go into the project Files folder and delete those files that now reside in dir.defaultexternal.
 

JonPM

Well-Known Member
Licensed User
Longtime User
Maybe file export your project and upload it here so we can give it a try.

Sent from my DROIDX using Tapatalk 2
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
@ Erel and JonPM and anyone that wants to take a shot at it.: Here is the project zipped.
 

Attachments

  • AssetsRogueFiles.zip
    9.6 KB · Views: 195
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I attached my project codeas a zipped file in the previous post as I was requested to, but nobody took a crack at it. Can someone take a look at the project code and see if they reproduce the same error I had.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
It seems that Basic4Android is adding these 'invisible' files.
The attached test project shows it.
There are three 'files?' shown in the FileList, they do exist with File.Exists but they are not found when trying to copy them.

Best regards.
 

Attachments

  • TestAssets2.zip
    5.5 KB · Views: 168
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Klaus: That is what I had mentioned in my previous posts. The rogue files were: database, images, sounds, Webkit . How do you get rid of them though, since they exist in the assets folder? Very strange. Let us hope it is not a bug in B4A.
Merci
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Erel should look at the problem with the 'invisible' files.

Do your file names have specific extensions ?
If yes you can check those before copying.
That's what I do when reading files with a given type from a folder.

Best regards.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Finally we have an answer to this grueling thread. That is why I had the try-end try block. Without it, the code would not work:

B4X:
Dim MyList As ListDim MyFile As String
Dim i As ShortDim FilePathSource As String          
FilePathSource=File.DirAssetsDim FilePathDest As String          
FilePathDest=File.DirDefaultExternal    
MyList.Initialize                      
MyList=File.ListFiles(FilePathSource)   
For i=0 To MyList.Size-1       
   MyFile=MyList.Get(i)   
   If MyFile.EndsWith(".bal")=False  Then      'do not copy the .bal files          
    Try     'To trap the 4 files Klaus calls invisible files.      
    'Msgbox(MyFile,"")        
    File.Copy(FilePathSource,MyFile,FilePathDest,MyFile)       
    Catch       
    End Try     
  End If   
 Next
 
Upvote 0
Top