重命名目录给出阳性结果code,但没有重命名 [英] Renaming directory gives positive result code, but didn't rename

查看:123
本文介绍了重命名目录给出阳性结果code,但没有重命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这只是表面,但低于code然而,应该重新命名我的目录中没有。所不同的只是一些资本 - 但AFAIK Android是完全区分大小写当涉及到的文件名。如Linux通常过。 重命名给出了一个真实的结果,表明操作成功。然而,在讨论的目录不重命名,它仍然有两个大写D的。 我有previously用同样的code到重命名/ DeadDropDroid到/.DeadDropDroid和工作正常。我每次运行C日志下面$ C $说:成功。

  oldBasePath =新的文件(Environment.getExternalStorageDirectory()+/.DeadDropDroid/);
如果(oldBasePath.exists()){
    如果(oldBasePath.renameTo(新文件(Environment.getExternalStorageDirectory()+/.DeaddropDroid/)))
        Log.v(TAG,重命名成功。);
    其他
        Log.v(TAG,重命名失败。);
    }
 

解决方案

看一看<一href="http://stackoverflow.com/questions/5407396/android-check-if-file-exists-with-case-sensitivity/5407535#5407535">this回答过类似的问题。重点内容是

默认情况下,SD卡格式化为FAT,其中preserves情况,但不区分大小写。

我做了一些检查,可以确认提及文件方法的工作原理区分大小写在SD卡上。你甚至无法检查 oldBasePath.exists()为IST也将返回如果小写目录版本存在,而不是大写版本。你要读取目录的内容和你比收到您的模式的文件/目录名。

重命名也将是一个两步法(通过一个临时文件),例如:

  .DeadDropDroid  - &GT; .DeadDropDroid_tmp  - &GT; .DeaddropDroid
 

I know it's only cosmetic but the below code should rename my directory however it doesn't. The difference is just some capitalisation - but afaik Android is fully case sensitive when it comes to filenames. Like Linux normally is too. The rename gives a true result, indicating the operation was successful. However the directory in question is NOT renamed, and it still has two capital D's. I have previously used the same code to rename from /DeadDropDroid to /.DeadDropDroid and that works fine. Every time I run the below code the log says "success".

oldBasePath = new File (Environment.getExternalStorageDirectory()+ "/.DeadDropDroid/");
if (oldBasePath.exists()) {
    if (oldBasePath.renameTo(new File(Environment.getExternalStorageDirectory()+ "/.DeaddropDroid/")))
        Log.v(TAG, "Rename success.");
    else
        Log.v(TAG, "Rename fail.");
    }

解决方案

Have a look at this answer to a similar question. The key content is

By default, the SD card is formatted as FAT, which preserves case but is case insensitive.

I did some checks and can confirm that the mentioned File methods work 'case insensitive' on the SD card. You even can not check oldBasePath.exists() as ist also will return trueif the LowerCase directory version exists instead of the UpperCase version. You have to read the directory content and compare the file/directory names you received with your pattern.

Renaming will also be a two step approach (via a temp File), e.g

.DeadDropDroid -> .DeadDropDroid_tmp -> .DeaddropDroid

这篇关于重命名目录给出阳性结果code,但没有重命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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