DosMove
Moves a file object to another location, and changes its name.
Syntax
DosMove(pszOld, pszNew)
Parameters
- pszOld (PSZ) - input
- Address of the old path name of the file or subdirectory to be moved.
- pszNew (PSZ) - input
- Address of the new path name of the file or subdirectory.
Return Code
- ulrc (APIRET) - returns
- DosMove returns the one of following values:
0 NO_ERROR 2 ERROR_FILE_NOT_FOUND 3 ERROR_PATH_NOT_FOUND 5 ERROR_ACCESS_DENIED 17 ERROR_NOT_SAME_DEVICE 26 ERROR_NOT_DOS_DISK 32 ERROR_SHARING_VIOLATION 36 ERROR_SHARING_BUFFER_EXCEEDED 87 ERROR_INVALID_PARAMETER 108 ERROR_DRIVE_LOCKED 206 ERROR_FILENAME_EXCED_RANGE 250 ERROR_CIRCULARITY_REQUESTED 251 ERROR_DIRECTORY_IN_CDS
Remarks
DosMove can be used to change only the name of a file or subdirectory, allowing the file object to remain in the same subdirectory. Global file-name characters are not allowed in the source or target name.
If the specified paths are different, the subdirectory location of the file object is changed also. If a drive is specified for the target, it must be the same as the one specified or implied by the source.
Attempts to move a parent subdirectory to one of its descendant subdirectories result in error code 251 (ERROR_DIRECTORY_IN_CDS) because a subdirectory cannot be both an ancestor and a descendant of the same subdirectory.
Attempts to move the current subdirectory or any of its ancestors for the current process, or any other process, will be rejected.
Attributes (times and dates) of the source file object are moved to the target. If read-only files exist in the target path, they are not replaced.
During initialization by an application, DosQuerySysInfo is called to determine the maximum path length allowed by the operating system.
DosMove can be used to change the case of a file on a drive that is controlled by a file system driver (FSD). The following example would change the name of the file to "File.Txt.".
DosMove("file.txt","File.Txt")
Example Code
This example moves the file "FIRST.DAT" to the directory "NEWDIR", renamed as "SECOND.DAT".
#define INCL_DOSFILEMGR /* File Manager values */ #define INCL_DOSERRORS /* DOS error values */ #include <os2.h> #include <stdio.h> HFILE hfFileHandle = 0L; /* File Handle */ ULONG ulAction = 0; /* Action taken */ UCHAR uchNewDirName[10] = "newdir"; /* New directory name */ PEAOP2 peaop2NewDirAttribute = NULL; /* New directory attributes */ UCHAR uchOldPathName[40] = "first.dat"; /* Old path name string */ UCHAR uchNewPathName[40] = "newdir\\second.dat"; /* New path name string */ APIRET rc = NO_ERROR; /* Return code */ int main(VOID) { /* Create a file "first.dat" in the current directory */ rc = DosOpen("first.dat", &hfFileHandle, &ulAction, 100L, FILE_NORMAL, FILE_CREATE | OPEN_ACTION_OPEN_IF_EXISTS, OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYNONE, 0L); if (rc != NO_ERROR) { printf("DosOpen error: return code = %u\n", rc); return 1; } rc = DosClose(hfFileHandle); /* Close the file (it contains junk) */ if (rc != NO_ERROR) { printf("DosClose error: return code = %u\n", rc); return 1; } /* Create a new subdirectory within the current directory */ rc = DosCreateDir(uchNewDirName, peaop2NewDirAttribute); if (rc != NO_ERROR) { printf("DosCreateDir error: return code = %u\n", rc); return 1; } /* Move the file "first.dat" from the current directory to the new directory "newdir", and rename it "second.dat" */ rc = DosMove(uchOldPathName, uchNewPathName); if (rc != NO_ERROR) { printf("DosMove error: return code = %u\n", rc); return 1; } else { printf("DosMove: Move from %s to %s complete.\n", uchOldPathName, uchNewPathName); } return NO_ERROR; }