简体   繁体   中英

MoveFile and MoveFileEx works weird if filenames are the same in DOS 8.3 style

Ok, I have files named

ANIME~1.MKV~FNH47B97
ANIME~1.MKV

It is FULL filenames. It is named so by user. And I want to rename the first one to ANIME~1.JPG. From OS point of view they seem to be the same files. And both MoveFile and MoveFileEx do nothing. They return OK and that's all.
Another weird situation is when we have, for example,

ANIME~2.MKV~FNH47B97
ANIME~3.MKV

And I want to rename the first one to ANIME~2.MKV OS founds that it's the same as ANIME~3.MKV and still does nothing.
It depends on the number of files with "the same dos 8.3 names" in the folder

Any way to workaround it? May be some additional actions/flags needed?

To summarise the discussion in the comments as an approximate answer: MoveFile(Ex) works on the full filenames, though it can find the source file by its short name, the destination file is taken to be the long name.

This means that the destination filename should not clash with any long or short filenames of existing files. This is probably why your second test-case fails. The first test-case probably fails for a similar reason; I've tried it with just those two files and MoveFile works with it.

It is possible to disable the generation of DOS style 8.3 shortnames, see KB121007 , but I really don't recommend it. It can cause lots of issues, see for instance this article . Also, this is a decision that should be left to the system administrator, not any application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM