Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Allowing the user to select a directory from the file system
-
Hello. I have begun writing a small script to play audio files contained in a certain directory (on the iCloud or in the iPhone file system). For this, I would like to allow the user to select the directory that contains the audio files. Looking at the documentation, I found that
dialogs.pick_document()
allows the user to select files from the file system. But when I test it, the dialog does not allow for a directory to be selected, only regular files. What I would like is for the user to be able to select a directory. It seems that if the right UTI is specified, this could be possible. I tried using the‘public.directory’
and‘public.folder’
types, but the dialog still does not allow me to select a directory. Would anyone have any idea as to what I need to do to allow the user to select a directory from the file system? I would really appreciate it. -
Try https://github.com/tdamdouni/Pythonista/blob/master/omz/File Picker.py
You may need to customize to hide non-folders.
-
Thanks again for your help. Have a good day again.
-
@jaalburquerque done in Folder_Picker
-
Would any of you know if it is possible to open a folder that is contained in the iPhone file system (“On My iPhone”) or in the iCloud Drive to play the audio files in that folder? The audio files are located in directories in both these locations.
-
@jaalburquerque yes, via thé Open External Files of Pythonista
-
Thanks. And would you be able to tell me how I might use the “FolderPicker” script in my own script to open a directory either “On My iPhone” or on the iCloud Drive?
-
@jaalburquerque First, you have to create your own folder in "On my iPhone " or "iCloud Drive".
Then, you have to give access to this folder by opening it once manually via Pythonista External Files. Then, you will need to know the full path to access to this folder by creating a small py script in this folder withimport editor print(editor.get_path())
and run it to know the path
For instance, on My iPhone, it will be something like/private/var/mobile/Containers/Shared/AppGroup/EF3F9065-AD98-4DE3-B5DB-21170E88B77F/File Provider Storage/MyFolder/a.py
-
Okay. I will try that. Thanks so much.
-
@jaalburquerque sorry, procédure not yet ended, ....then you have to use this path in folder_picker
py_dir = folder_picker_dialog('Select a folder', root_dir='/private/var/mobile/Containers/Shared/AppGroup/EF3F9065-AD98-4DE3-B5DB-21170E88B77F/File Provider Storage/')
-
@jaalburquerque For instance, in "on my iPad ", I have some private folders, and I can see them like
-
Okay. It is very clear. Thanks again.