Android Question Location of Files (Core) Library

Atom058

Member
Licensed User
Hello - I am a new user, so please be kind. I am trying to write a small Android App to read a file stored on the external SD card, do some simple processing and then display a one-line result and store that in a summary file located in the same directory as the data file on the SD card. I have poured through the B4A documentation and see that there is a library called Files (Core) and it looks like where I should start. I looked in my B4A library list and it is not there. I searched the forum and found one reference to someone else with the same problem and they were told that it should have been installed when I installed B4A. It was not in my case. I did some more searching and was directed to ExternalStorage, which looks promising, but it specifically says that it will not run at Android versions less than 5. My device is 4.2.2. So, my questions are, Is Files(Core) available somewhere to add to my libraries and if so, is it supported by 4.2.2? Thanks.
 

Atom058

Member
Licensed User
DonManfred - Sorry, I was confused. I thought that Files (Core) was a separate library and not a part of Core. I will check that out.

Erel, Unfortunately, this device (a laboratory instrument) uses an embedded android device as it's controller. The manufacturer says that it can not be upgraded, so it is stuck at 4.2.2. If I hook this to my PC, I can see the folder on the SD card that has the data files in it, so I know the full path to the data files (/storage/sdcard0/export/spectra/). Will the Files functions work with 4.2.2? Any other suggestion (other than "give up")? Thanks!
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
so I know the full path to the data files (/storage/sdcard0/export/spectra/).

I do not have any Android 4.2.2 device

Try the following code on your Device

B4X:
    Dim files As List = File.ListFiles("/storage/sdcard0/export/spectra/")
    If files.IsInitialized And files.Size>0 Then
        For Each f As String In files
            Log(f)
        Next
    End If
Does it log the files in the spectra folder?
 
Upvote 0

Atom058

Member
Licensed User
DonManfred - What I did was take the "MyFirstProgram" tutorial app, which shows 2 numbers and you are supposed to add them together, enter the answer and then it will tell you if you were correct. (this app runs fine on the 4.2.2 device). I added a button called btnFiles, pasted your code and ran it on the device

B4X:
Sub btnFiles_Click
    Dim files As List = File.ListFiles("/storage/sdcard0/export/spectra/")
    If files.IsInitialized And files.Size>0 Then
        For Each f As String In files
            Log(f)
        Next
    End If
End Sub

And nothing happens. Again, I am new with this, so please let me know if I did everything correctly... Where are the files "logged" to?
 
Upvote 0

Atom058

Member
Licensed User
DonManfred - YES! I see the files listed in the IDE log window - This is with the original code, not the single line code suggested by @Mahares... I tried the other code and it works, too. OK - So it looks like I can access the SD card on a 4.2.2 device! This is good news! Thank you all! I will take what I have learned and see how far I can get - Next task is to put this output into a listbox so that the user can select a file for processing. Any additional pointers / suggestions is greatly appreciated. Thanks again!
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
not the single line code suggested by @Mahares.
I did not mean for you to just use the single line by itself. I meant for you to replace the original line in Manfred's code with the one I put. I still do not know what the final code you used that worked is. You did not post it.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I still do not know what the final code you used that worked is. You did not post it.
Agree

As from how i did understand his last answer i am expecting both are working.
B4X:
Dim files As List = File.ListFiles(File.DirRootExternal & "/export/spectra")
and
B4X:
Dim files As List = File.ListFiles("/storage/sdcard0/export/spectra/")
 
Upvote 0

Atom058

Member
Licensed User
Both versions worked fine:

B4X:
Sub btnFiles_Click
    'Dim files As List = File.ListFiles("/storage/sdcard0/export/spectra/")  'Works!
    Dim files As List = File.ListFiles(File.DirRootExternal & "/export/spectra")  'Works, too!
    If files.IsInitialized And files.Size>0 Then
        For Each f As String In files
            Log(f)
        Next
    End If
End Sub

And probably the one using File.DirRootExternal is the better way to go, right?... Thanks to you both!
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
And probably the one using File.DirRootExternal is the better way to go, right?.
The reason you want to use File.DirRootExternal (preferred) is because it is more uniform. If , for some reason you have a different model device , it may refer to DirRootExternal with a different name like: /storage/sdcard0/.... and maybe another name like: /storage/emulated/0/.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…