重命名目录给出阳性结果code,但没有重命名重命名、阳性、结果、目录

2023-09-03 20:55:15 作者:你怕黑我就送你整片星空i

我知道这只是表面,但低于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,重命名失败。);
    }
 

解决方案

看一看this回答过类似的问题。重点内容是

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

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

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

  .DeadDropDroid  - > .DeadDropDroid_tmp  - > .DeaddropDroid
 

PowerDesigner里找不到unique code,无法允许重命名,急

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