Android Question ExternalStorage Example and SubFolders

dank

Member
Licensed User
Longtime User
Hi. I'm sure I'm missing something simple, but I've looked for the solution but can't find it. On my phone, I have a folder called Data, and it has several subfolders -- let's call them Photos and Docs. When I use the example program for ExternalStorage, I get the list of subfolders and filenames, but the filenames aren't separated by their folder names. It looks like I get photo names in the Docs folder and vice versa, for example. How can I get a clean list of files for each of the three folders?

Thanks in advance!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
f you write the data on External storage you can create folder vice versa.
Sorry to say but this code is completely wrong. It also has nothing to do with the question.
1. You should never see File.DirDefaultExternal in your code.
2. No permission is required to access rp.GetSafeDirDefaultExternal.
3. The correct way to create a subfolder under GetSafeDirDefaultExternal is by passing the folder name as the parameter (instead of the empty string).
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The data folder is not accessible in Android 11+.

You never get full paths with ExternalStorage as it is related to the user chosen root folder. It isn't difficult to get the full paths relatively to that folder. The example does track the parent folders paths.

In most cases it is a mistake to use ExternalStorage. Better to use ContentChooser + SaveAs (see the TextEditor example).
 
Upvote 0

dank

Member
Licensed User
Longtime User
Thanks for your replies. I apologize that my question wasn't clear enough.

I'm trying to write a program, for my own use, to backup existing folders and files to a NAS drive. I created the folder "data" for my various projects (emulating what I do on my PC) and have a subfolder for each project. The files can be images, text files, databases, etc.

Using the ExternalStorage example, I can get the filenames and have been able to copy over the individual files to the NAS drive. Is it possible to get the full folder path for each file? Or, do I need to build up the full folder names one level at a time?

Thanks again.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…