如何从内存中获取android手机的所有文件夹名并在文本字段中显示?

2024-04-25 15:09:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我要做的是查看文本字段中特定位置的所有文件夹名称。例如,给定的数据路径是-

android/data/

在这里,在数据路径中我们有一些文件夹,比如com.facebook.katanacom.android.browsercom.android.calendar等等。现在我想做的是在文本字段中显示所有文件夹的名称。有什么办法吗?你知道吗


Tags: 数据文本路径browser文件夹名称comdata
1条回答
网友
1楼 · 发布于 2024-04-25 15:09:46

解决方案/提示如下。你知道吗

代码段

<FileList>:
    BoxLayout:
        size: root.size
        pos: root.pos
        orientation: "vertical"
        FileChooserListView:
            id: filechooser
            path: './'    # 'android/data'
            filters: ['com.*']

FileChooser » path

path

path is a StringProperty and defaults to the current working directory as a unicode string. It specifies the path on the filesystem that this controller should refer to.

Warning

If a unicode path is specified, all the files returned will be in unicode, allowing the display of unicode files and paths. If a bytes path is specified, only files and paths with ascii names will be displayed properly: non-ascii filenames will be displayed and listed with questions marks (?) instead of their unicode characters.

FileChooser » filters

filters

filters specifies the filters to be applied to the files in the directory. filters is a ListProperty and defaults to []. This is equivalent to ‘*’ i.e. nothing is filtered.

The filters are not reset when the path changes. You need to do that yourself if desired.

There are two kinds of filters: patterns and callbacks.

Patterns

e.g. [‘*.png’]. You can use the following patterns:

Pattern Meaning * matches everything ? matches any single character [seq] matches any character in seq [!seq] matches any character not in seq

Callbacks

You can specify a function that will be called for each file. The callback will be passed the folder and file name as the first and second parameters respectively. It should return True to indicate a match and False otherwise.

相关问题 更多 >