如果文件区分大小写存在的android检查?大小写、存在、文件、android

由网友(bt就是b里有个t)分享简介:我要改变文件夹的标题外壳。基本上,应用程序启动时我想看看旧外壳,如果它仍然存在重命名。所以,在我的测试到目前为止,机器人忽略了外壳,并报告该文件夹套管作为任何你发送的,所以基本上I have to change the title casing of a folder. Basically, on app start...

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

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
}
阅读全文

相关推荐

最新文章