The MoveFileEx function renames an existing file or directory.
BOOL MoveFileEx(
LPCTSTR lpExistingFileName, |
// address of name of the existing file |
LPCTSTR lpNewFileName, |
// address of new name for the file |
DWORD dwFlags |
// flag to determine how to move file |
); |
When moving a file, the destination can be on a different file system or drive. If the destination is on another drive, you must set the MOVEFILE_COPY_ALLOWED flag in dwFlags.
When moving a directory, the destination must be on the same drive.
Value |
Meaning |
MOVEFILE_COPY_ALLOWED | |
If the file is to be moved to a different volume, the function simulates the move by using the CopyFile and DeleteFile functions. Cannot be combined with the MOVEFILE_DELAY_UNTIL_REBOOT flag. | |
MOVEFILE_DELAY_UNTIL_REBOOT | |
Windows NT only: The function does not move the file until the operating system is restarted. The system moves the file immediately after AUTOCHK is executed, but before creating any paging files. Consequently, this parameter enables the function to delete paging files from previous startups. | |
MOVEFILE_REPLACE_EXISTING | |
If a file of the name specified by lpNewFileName already exists, the function replaces its contents with those specified by lpExistingFileName. | |
MOVEFILE_WRITE_THROUGH | |
Windows NT only: The function does not return until the file has actually been moved on the disk. Setting this flag guarantees that a move perfomed as a copy and delete operation is flushed to disk before the function returns. The flush occurs at the end of the copy operation. This flag has no effect if the MOVEFILE_DELAY_UNTIL_REBOOT flag is set. |
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.
An application cannot specify both MOVEFILE_DELAY_UNTIL_REBOOT and MOVEFILE_COPY_ALLOWED for dwFlags. Function calls that do so will fail.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\
Control\Session Manager\PendingFileRenameOperations
The key is of type REG_MULTI_SZ. Each rename operation is a pair of NULL-terminated strings. The system uses these registry entries to complete the operation at reboot in the same order that they were issued.
For example, on Windows NT, the following code fragment creates registry entries that delete szDstFile and rename szSrcFile to be szDstFile at reboot:
MoveFileEx(szDstFile, NULL, MOVEFILE_DELAY_UNTIL_REBOOT); MoveFileEx(szSrcFile, szDstFile, MOVEFILE_DELAY_UNTIL_REBOOT);
szDstFile\0\0 szSrcFile\0szDstFile\0\0
GetWindowsDirectory(szWinInitFile, uSize); lstrcat(szWinInitFile, "\\WININIT.INI"); WritePrivateProfileString("Rename", "NUL", szDstFile, szWinInitFile); WritePrivateProfileString("Rename", szDstFile, szSrcFile, szWinInitFile);
CopyFile, DeleteFile, GetWindowsDirectory, lstrcat, MoveFile, WritePrivateProfileString
file: /Techref/os/win/api/win32/func/src/f57_15.htm, 7KB, , updated: 2000/4/7 11:19, local time: 2024/11/28 18:13,
3.149.23.123:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://sxlist.com/TECHREF/os/win/api/win32/func/src/f57_15.htm"> MoveFileEx</A> |
Did you find what you needed? |
Welcome to sxlist.com!sales, advertizing, & kind contributors just like you! Please don't rip/copy (here's why Copies of the site on CD are available at minimal cost. |
Welcome to sxlist.com! |
.