Renaming directory gives positive result code, but didn't rename
I know it's o开发者_JAVA百科nly 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 true
if 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
精彩评论