如果文件区分大小写存在的android检查? [英] android check if file exists with case sensitivity?

查看:274
本文介绍了如果文件区分大小写存在的android检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要改变文件夹的标题外壳。基本上,应用程序启动时我想看看旧外壳,如果它仍然存在重命名。所以,在我的测试到目前为止,机器人忽略了外壳,并报告该文件夹套管作为任何你发送的,所以基本上

I have to change the title casing of a folder. Basically, on app startup I want to look for the old casing, and rename it if it is still there. So far in my tests, android ignores the casing, and reports the folder casing as whatever you send in. So basically

new File(PATH_WITH_OLD_CASING) == new File(PATH_WITH_NEW_CASING)

和它似乎也给您发送的绝对路径,没有问候报告它在文件系统中实际命名。所以

and it also seems to report the absolute path that you send in, without regards to what it is actually named in the file system. so

new File(PATH_WITH_OLD_CASING).getAbsolutePath() == PATH_WITH_OLD_CASING;

new File(PATH_WITH_NEW_CASING).getAbsolutePath() == PATH_WITH_NEW_CASING;

即使它们指的是同一个文件。

even though they refer to the same file.

所以我努力想出一个方法来确定是否旧的外壳仍然存在。我大概可以做父目录listFiles拿到外壳,但其SD卡的根目录下,并不真的想这样做,每次应用程序启动时(似乎并不像一个很干净的解决方案)。

So I am struggling to come up with a way to determine if the old casing is still there. I can probably do a listFiles on the parent directory to get the casing, but its the root of the SD Card, don't really want to do that everytime the app starts (doesn't seem like a very clean solution).

任何想法?

推荐答案

更​​新:我想出了

if (parentDirectory.listFiles(new FilenameFilter() {
    @Override
    public boolean accept(File dir, String name) {
        return name.contentEquals(DEPRECATED_FILE_NAME);
    }
   }).length > 0){
//old file exists
}

这篇关于如果文件区分大小写存在的android检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆