Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
liming1010 opened this issue Jan 2, 2024 · 7 comments
Open

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

liming1010 opened this issue Jan 2, 2024 · 7 comments

Comments

@liming1010
Copy link

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等

@youlookwhat
Copy link
Owner

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

@liming1010
Copy link
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
Copy link
Owner

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

@liming1010
Copy link
Author

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

@youlookwhat
Copy link
Owner

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

@liming1010
Copy link
Author

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

@youlookwhat
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants