'How can I check if treeUri is empty?
I want to check if a treeUri has any files in it or if its empty, so I can delete the Folder. Ive tried listFiles but comes up with Landrodix.etc. and not the actual list. Thanks.
On Folder select
Intent intent = new
Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
startActivityForResult(intent, 42);
Activity Result
DocumentFile dfile =
DocumentFile.fromTreeUri(this, uri);
DocumentFile[] de = dfile.listFiles();
st = de.toString();
Solution 1:[1]
I figured it out
Uri uri = Uri.parse(muri);
DocumentFile directory =
DocumentFile.fromTreeUri(this, uri);
DocumentFile[] files =
directory.listFiles();
double w3 =
Double.parseDouble(Integer.toString
(files3.length));
feel free to use this code no credits required it just .length
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |