Skip to content

你好,怎么知道获取的文件列表是类型? #6

Open
@liming1010

Description

smb.listFile(object : OnReadFileListNameCallback {
            override fun onFailure(message: String) {

            }

            override fun onSuccess(fileNameList: List<String>) {
                files = fileNameList
                for (i in fileNameList) {
                    Log.v("xxx", i)
                }
            }
        })

类型是string,怎么知道文件类型,比如zip, txt, 文件夹,jpg等

Activity

youlookwhat

youlookwhat commented on Jan 2, 2024

@youlookwhat
Owner

这是文件路径,应该可以通过路径得到后缀名吧,通过 / 拆分,然后通过 . 截取后面的后缀名

liming1010

liming1010 commented on Jan 3, 2024

@liming1010
Author

开始想过这种方法,但是不行,比如一个文件它没有后缀名,但它不是文件夹,就不好整
后面又重新实现了一个OnReadFileInformationCallback,返回的是Information,但是也不能判断是不是文件夹

fun listFileInformation(path: String = "", searchPattern: String? = null, callback: OnReadFileInformationCallback) {
        if (bySmb?.getConnectShare() == null) {
            callback.onFailure("配置错误")
            return
        }
        val fileNameList: ArrayList<FileIdBothDirectoryInformation> = arrayListOf<FileIdBothDirectoryInformation>()
        try {
            val list = bySmb?.getConnectShare()!!.list(path, searchPattern)
            callback.onSuccess(list)
        } catch (e: Exception) {
            e.printStackTrace()
            callback.onFailure(e.message ?: "获取文件名失败")
        }
    }
youlookwhat

youlookwhat commented on Jan 3, 2024

@youlookwhat
Owner

一个文件它没有后缀名,这个要判断类型本来就不好处理,据我所知需要将文件下载到本地,然后再通过什么方式判断。

liming1010

liming1010 commented on Jan 4, 2024

@liming1010
Author

File类里面有个isDirectory()方法,就是有没有办法让它返回一个File类型的list

youlookwhat

youlookwhat commented on Jan 5, 2024

@youlookwhat
Owner

你是说通过文件流得到文件类型:通过文件流获取文件类型

liming1010

liming1010 commented on Jan 5, 2024

@liming1010
Author

是的,就是这种,就是怎么拿到这个文件流 ^_^

youlookwhat

youlookwhat commented on Jan 6, 2024

@youlookwhat
Owner

你有文件的路径了,不是就可以得到文件流了嘛,你相当于有了这个
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      你好,怎么知道获取的文件列表是类型? · Issue #6 · youlookwhat/BySMB