MoveFile

The MoveFile function renames an existing file or a directory (including all its children).

BOOL MoveFile(
  LPCTSTR lpExistingFileName, // pointer to the name of the existing file
  LPCTSTR lpNewFileName       // pointer to the new name for the file
);
 

Parameters

lpExistingFileName
Pointer to a null-terminated string that names an existing file or directory.
lpNewFileName
Pointer to a null-terminated string that specifies the new name of a file or directory. The new name must not already exist. A new file may be on a different file system or drive. A new directory must be on the same drive.

Return Values

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The MoveFile function will move (rename) either a file or a directory (including all its children) either in the same directory or across directories. The one caveat is that the MoveFile function will fail on directory moves when the destination is on a different volume.

QuickInfo

  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Requires version 1.0 or later.
  Header: Declared in winbase.h.
  Import Library: Use kernel32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT.

See Also

File I/O Overview, File Functions, CopyFile, MoveFileEx