SAF - how do I recursively list directory?

I can do it with FileTools with


But I need to do it with SAF. I tried but nothing worked, please help
P.S. don't look at variable error, i made this block only for screenshot

image

will try to list files in a directory

not sure you can do this recursively for subfolders, you would need to use a file extension to do this, or build a procedure that uses the file component blocks to do the same.

Try this one:

Blocks

I meant with all dirs and subdirs. Like this

['/Downloads/fl.txt', '/Downloads/doc.pdf', '/Downloads/ai2.aia', ['/Downloads/SUBDIR/text.txt', '/Downloads/SUBDIR/RandomNum.py'], [None, '/Downloads/EmptyDir']]

I think this is not possible with SAF. You have to open each folder individually with SAF and grant access to be able to list its contents.

Note: You cannot open /Download and the root directory of the external storage with SAF (but all others, including /Downloads).

I don't need subfolders anymore (they're not needed in my app, i understood it only today). Sorry for asking. But anyway thanks for answering

If I understand the question correctly then yes it's possible to list dirs recursively.

saf.aia (33.1 KB)

2 Likes

Yes, but you have to select each subfolder individually.

I think I found a way to list also files from subfolders without selecting them individually:

How about blocks?...

This version lists files from the root dir, subfolders and all files from subfolders at once:

1 Like

How about testing and giving feedback first?

Oh sorry, forgot to say it. App works exactly how I wanted, I just really wanted to see the blocks

Added.

These two blocks expanded please ?

image

image

Of couse: SAF_listFilesfromSubFolders.aia (63.0 KB)

I see it doesn't recurse if there are sub/sub folders, e.g.

Documents/subfolder/subsubfolder

Yes, but is it really necessary to list even 3rd and 4th level subfolders? However, since you now know the logic, in principle it should be possible.

I figured out a clunky workaround for the stupid /Download folder restriction using SAF.

  • In Download, add a subfolder called Download
  • move/store all your files in Download to Download/Download (how to do this programmatically is of course another issue...)
  • you can now access Download/Download using SAF Document Tree

no need to do this is if you only want to OPEN_DOCUMENT/GET_CONTENT.

Well, this is nothing new, because the same applies to the root dir of the external storage. This cannot be selected, but any subfolder (except the root dir of the /Download folder) can be selected. Therefore, the same reasoning/logic applies to the /Download directory as well.

Apart from that, who would this help? Since the app has no access to non-media files in this folder that it did not create itself, the only option would be for the user to do it manually on their device. Who would be willing to do that and why?