Android Question Reading folder structure and getting file info

Mark Stuart

Active Member
Licensed User
Longtime User
Hi all,
Im building an app that needs to read the folder structure and when it discovers files in the last folder, read those file names and the id3tags of each file. The files are .mp3.

The folder structure contains Artist Name/ Album Name / then .mp3 songs.
I've copied this structure from my PC by attaching the device to it and copying all folders and .mp3 files.

An artist folder can contain more than one folder (at least one), as albums. An album then contains the songs (.mp3 file) of the album.

All the folders and files on the device have been copied into a subfolder (named: MyMusic) under the Music folder.

Expected behavior for the app:
1. The app would allow the user to select the MyMusic folder.
2. The code would then read each folder and subflowers and then read the .mp3 files. As the code is reading the name of the folder, it has to keep track of that (maybe in a List) and after reaching the last folder with the .mp3 files, the code would then write all that folders and files info to SQlite tables on the device.
Tables: artist, albums, and songs.
3. The main layout will display the artist names in a listview.
4. When selecting an artist, the artists albums will display horizontally in a customlistview to the right of the artists.
5. When an album is selected, the albums songs will list into a customlistview below the albums.
6. The user can then play a selected song or another option to play the whole album.

I've experimented with the ExternalStorage library and gotten stuck. I have gone thru 5 versions of this and so can't really give you any code that makes sense.

I hope I have explained everything well enough for you to help out with this.

Regards,
Mark Stuart

ps: I started another post last week, mentioning that I'm trying ChatGPT to help write the code, but it's failing miserably.
 
Last edited:

Cableguy

Expert
Licensed User
Longtime User
I have a sample code for you, but I'm on my phone right now. Give me a couple of hours, then I will be free to send you some examples
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
I am trying to find it, I know I have it somewhere!
Dahm, I just can't find it.... Still, I can send you in the right direction.
You will need to do establish a few loops and use File.ListFiles, which returns a list, and then go through each result checking if its a Folder using File.isDirectory, and if true, dig another loop until you get only files.
Since you already know how many levels you have in your file tree, should be too difficult to extract this info, and present it using a treeview or a treelistview

try the following examples as starting point, even if its b4a, its cross-platform, so it should work with b4j with minor changes
 
Last edited:
Upvote 0
Top