Skip to content

Move Rename File

A one-line C program that renames a file on the desktop using MoveFile.

Published Jan 9, 1998

The shortest possible demonstration of MoveFile: same directory, new name, and the file is renamed. Because both paths are on the same volume it completes instantly as a metadata operation; across volumes Windows falls back to copy-then-delete (or fails if the destination exists). Check the return value in real code - this snippet does not - and use MoveFileEx with MOVEFILE_REPLACE_EXISTING when you want overwrite semantics.

#include <Windows.H>
#include <Stdio.H>

int main()
{
    MoveFile("c:/windows/desktop/aaa.bmp","c:/windows/desktop/bbb.bmp");
    return 0;
}

For rename-only operations on modern systems, RenameFile (Vista+) or NtSetInformationFile with FileRenameInfo give you more control over collision handling.

An unhandled error has occurred. Reload 🗙