Open knyipab opened 2 years ago
termux-saf-realname
returns to name of the file
You can do that with termux-saf-stat. I recommend jq
to use JSON in the shell, it's also in the Termux repo.
To get the name just use termux-saf-stat URI | jq -r '.name'
.
termux-saf-realpath
returns the URI in path. If it is online storage (e.g. GDrive), then perhaps return a empty string
Do you mean the path of the real file? There may not be a real file involved, only for the MediaStore, which you can already access with termux-setup-storage
, and for the SD card and internal storage, which you can't access without the SAF or without root anyways.
Hi. Thanks a lot for the answer in realname
!
For realpath
, the use case is below:
Let's say a Termux program asks a user to pick a folder (termux-saf-managedir
) or a file (termux-storage-get
). If the returned URI actually refers to a file/folder under the shared storage granted by termux-setup-storage
, it would be great to have termux-saf-realpath
to convert the URI back to file path and avoid the hassle handling URI. If it isn't, perhaps return a failure (like unix realpath
can fail).
I, personally, highly prefer such way Termux interact with user (in GUI) to specify which file/folder in shared storage to work on. So SAFAPI and StorageGetAPI can do more than just granting URI access, but also offer the functionality "Open ..." resembling many desktop GUI applications (this is still a gap in Termux. It can't be done with am start
, neither app_process
)
Note that termux-storage-get
does not return a URI in the current implementation, so I made a pull requests here to empower the tool. I could trim some functionalities if that pull request is too much.
I really appreciate the new SAF API. On top of the current utils, it would be good to have
realpath
equivalent and get name of the file. Feature descriptiontermux-saf-realpath
returns the URI in path. If it is online storage (e.g. GDrive), then perhaps return a empty stringtermux-saf-realname
returns to name of the file Reference implementation Nasib's answer in this stackoverflow post seems promising to handle media files. Many more stackoverflow posts should help.I may make pull requests if it's preferred and when I have time to write and test the codes. Thanks!