BOOL SetRootPath(TCHAR *oldpath, TCHAR *InPath) { TCHAR OutPath[MAX_PATH]; TCHAR OutPathTemp[MAX_PATH]; /* Retrieve the full path name from the (possibly relative) InPath */ if (GetFullPathName(InPath, MAX_PATH, OutPathTemp, NULL) == 0) goto Fail; /* Convert the full path to its correct case. * Example: c:\windows\SYSTEM32 => C:\WINDOWS\System32 */ GetPathCase(OutPathTemp, OutPath); /* Use _tchdir, since unlike SetCurrentDirectory it updates * the current-directory-on-drive environment variables. */ if (_tchdir(OutPath) != 0) goto Fail; /* Keep original drive in ordinary CD/CHDIR (without /D switch). */ if (oldpath != NULL && _tcsncicmp(OutPath, oldpath, 2) != 0) SetCurrentDirectory(oldpath); return TRUE; Fail: ConErrFormatMessage(GetLastError()); nErrorLevel = 1; return FALSE; }
BOOL SetRootPath(TCHAR *oldpath, TCHAR *InPath) { TCHAR OutPath[MAX_PATH]; TCHAR OutPathTemp[MAX_PATH]; /* The use of both of these together will correct the case of a path where as one alone or GetFullPath will not. Exameple: c:\windows\SYSTEM32 => C:\WINDOWS\system32 */ if (GetFullPathName(InPath, MAX_PATH, OutPathTemp, NULL)) { GetPathCase(OutPathTemp, OutPath); /* Use _tchdir, since unlike SetCurrentDirectory it updates * the current-directory-on-drive environment variables. */ if (_tchdir(OutPath) != 0) { ConErrFormatMessage(GetLastError()); nErrorLevel = 1; return FALSE; } /* Keep original drive in ordinary CD/CHDIR (without /D switch). */ if (oldpath != NULL && _tcsncicmp(OutPath, oldpath, 2) != 0) SetCurrentDirectory(oldpath); } return TRUE; }