I want to simulate a specific case of the UNIX rename()
function to rename directories. Its MAN page specifies:
oldpath can specify a directory. In this case, newpath must either not exist, or it must specify an empty directory.
I want to simulate the last case:
newpath exists and is empty.
So I have created the directories foo_dir
and bar_dir
and called MoveFileEx()
in order to rename foo_dir
to bar_dir
. Here is the code without error management:
mkdir("foo_dir");
mkdir("bar_dir");
MoveFileEx("foo_dir", "bar_dir", MOVEFILE_REPLACE_EXISTING)
But MoveFileEx()
always fails with error 5 (access denied). I have tried with other flags for MoveFileEx()
without success.
Must I manually remove bar_dir
if it exists and is empty before calling MoveFileEx()
? Or is there another solution?
I have not tried ReplaceFile()
yet.