Add new thing to cd.
authorMagnus Olsen <magnus@greatlord.com>
Fri, 20 May 2005 12:55:09 +0000 (12:55 +0000)
committerMagnus Olsen <magnus@greatlord.com>
Fri, 20 May 2005 12:55:09 +0000 (12:55 +0000)
Make cd pr* working

svn path=/trunk/; revision=15432

reactos/subsys/system/cmd/internal.c

index 56d73f4..e427250 100644 (file)
@@ -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());