From 67c71ced7cb009d9bff3b93d5fa45050032687bb Mon Sep 17 00:00:00 2001 From: Magnus Olsen Date: Fri, 20 May 2005 12:55:09 +0000 Subject: [PATCH] Add new thing to cd. Make cd pr* working svn path=/trunk/; revision=15432 --- reactos/subsys/system/cmd/internal.c | 48 ++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/reactos/subsys/system/cmd/internal.c b/reactos/subsys/system/cmd/internal.c index 56d73f47109..e4272500950 100644 --- a/reactos/subsys/system/cmd/internal.c +++ b/reactos/subsys/system/cmd/internal.c @@ -157,6 +157,11 @@ INT cmd_chdir (LPTSTR cmd, LPTSTR param) LPTSTR dir; /* pointer to the directory to change to */ LPTSTR lpOldPath; size_t size, str_len; + WIN32_FIND_DATA FileData; + HANDLE hSearch; + DWORD dwAttrs; + BOOL fFinished = FALSE; + /*Should we better declare a variable containing _tsclen(dir) ? It's used a few times, but on the other hand paths are generally not very long*/ @@ -242,6 +247,49 @@ INT cmd_chdir (LPTSTR cmd, LPTSTR param) if (!SetCurrentDirectory (dir)) { + + hSearch = FindFirstFile(dir, &FileData); + if (hSearch == INVALID_HANDLE_VALUE) + { + ConOutFormatMessage(GetLastError()); + free (lpOldPath); + lpOldPath = NULL; + return 1; + } + + + while (!fFinished) + { + dwAttrs = GetFileAttributes(FileData.cFileName); +#ifdef _DEBUG + DebugPrintf(_T("Search found folder :%s\n"),FileData.cFileName); +#endif + if ((dwAttrs & FILE_ATTRIBUTE_DIRECTORY)) + { + FindClose(hSearch); + // change folder + if (!SetCurrentDirectory (FileData.cFileName)) + { + ConOutFormatMessage(GetLastError()); + free (lpOldPath); + lpOldPath = NULL; + return 1; + } + + + return 0; + } + + else if (!FindNextFile(hSearch, &FileData)) + { + FindClose(hSearch); + ConOutFormatMessage(GetLastError()); + free (lpOldPath); + lpOldPath = NULL; + return 1; + } + } + //ErrorMessage (GetLastError(), _T("CD")); ConOutFormatMessage(GetLastError());