diff --git a/reactos/subsys/system/cmd/cmd.h b/reactos/subsys/system/cmd/cmd.h index 3185d7dc7f4..dc0bd57bb75 100644 --- a/reactos/subsys/system/cmd/cmd.h +++ b/reactos/subsys/system/cmd/cmd.h @@ -300,6 +300,7 @@ BOOL IsValidPathName (LPCTSTR); BOOL IsExistingFile (LPCTSTR); BOOL IsExistingDirectory (LPCTSTR); BOOL FileGetString (HANDLE, LPTSTR, INT); +VOID GetPathCase(TCHAR *, TCHAR *); #define PROMPT_NO 0 #define PROMPT_YES 1 diff --git a/reactos/subsys/system/cmd/internal.c b/reactos/subsys/system/cmd/internal.c index c8e62e8deb6..dad875c7521 100644 --- a/reactos/subsys/system/cmd/internal.c +++ b/reactos/subsys/system/cmd/internal.c @@ -241,8 +241,8 @@ BOOL SetRootPath(TCHAR *InPath) /* 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 */ - GetShortPathName(OutPathTemp, OutPathTemp2, MAX_PATH); - GetLongPathName(OutPathTemp2, OutPath, MAX_PATH); + GetFullPathName(OutPathTemp, MAX_PATH, OutPathTemp2, NULL); + GetPathCase(OutPathTemp2, OutPath); fail = SetCurrentDirectory(OutPath); if (!fail) @@ -395,19 +395,19 @@ INT cmd_chdir (LPTSTR cmd, LPTSTR param) _tcscat(szFinalPath,f.cFileName); if ((f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) - { + { if(!SetRootPath(szFinalPath)) { /* Change for /D */ if(bChangeDrive) - { - _tcsupr(szFinalPath); - GetLongPathName(szFinalPath, szPath, MAX_PATH); - SetCurrentDirectory(szPath); - } + { + _tcsupr(szFinalPath); + GetPathCase(szFinalPath, szPath); + SetCurrentDirectory(szPath); + } return 0; } - + } }while(FindNextFile (hFile, &f)); diff --git a/reactos/subsys/system/cmd/misc.c b/reactos/subsys/system/cmd/misc.c index bb7108100ad..d581f621470 100644 --- a/reactos/subsys/system/cmd/misc.c +++ b/reactos/subsys/system/cmd/misc.c @@ -68,6 +68,46 @@ TCHAR cgetchar (VOID) #endif /* _UNICODE */ } +/* + * Takes a path in and returns it with the correct case of the letters + */ +VOID GetPathCase( TCHAR * Path, TCHAR * OutPath) +{ + INT i = 0; + _tcscpy(OutPath, _T("")); + TCHAR TempPath[MAX_PATH]; + WIN32_FIND_DATA FindFileData; + HANDLE hFind; + _tcscpy(TempPath, _T("")); + + + for(i = 0; i < _tcslen(Path); i++) + { + if(Path[i] != _T('\\')) + { + _tcsncat(TempPath, &Path[i], 1); + if(i != _tcslen(Path) - 1) + continue; + } + /* Handle the base part of the path different. + Because if you put it into findfirstfile, it will + return your current folder */ + if(_tcslen(TempPath) == 2 && TempPath[1] == _T(':')) + { + _tcscat(OutPath, TempPath); + _tcscat(OutPath, _T("\\")); + _tcscat(TempPath, _T("\\")); + } + else + { + hFind = FindFirstFile(TempPath,&FindFileData); + _tcscat(TempPath, _T("\\")); + _tcscat(OutPath, FindFileData.cFileName); + _tcscat(OutPath, _T("\\")); + CloseHandle(hFind); + } + } +} /* * Check if Ctrl-Break was pressed during the last calls