Author: jmorlan
Date: Mon Jan 19 11:29:21 2009
New Revision: 38946
URL:
http://svn.reactos.org/svn/reactos?rev=38946&view=rev
Log:
cmd_rmdir: Implement ability to remove multiple directories with one command.
Modified:
trunk/reactos/base/shell/cmd/internal.c
Modified: trunk/reactos/base/shell/cmd/internal.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/internal.c?…
==============================================================================
--- trunk/reactos/base/shell/cmd/internal.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/internal.c [iso-8859-1] Mon Jan 19 11:29:21 2009
@@ -542,16 +542,15 @@
}
INT cmd_rmdir (LPTSTR param)
{
- TCHAR dir[MAX_PATH]; /* pointer to the directory to change to */
TCHAR ch;
INT args;
- LPTSTR *arg = NULL;
+ INT dirCount;
+ LPTSTR *arg;
INT i;
BOOL RD_SUB = FALSE;
BOOL RD_QUIET = FALSE;
- HANDLE hFile;
- WIN32_FIND_DATA f;
INT res;
+ INT nError = 0;
TCHAR szFullPath[MAX_PATH];
if (!_tcsncmp (param, _T("/?"), 2))
@@ -560,19 +559,8 @@
return 0;
}
- nErrorLevel = 0;
-
arg = split (param, &args, FALSE);
-
- if (args == 0)
- {
- /* only command given */
- error_req_param_missing ();
- freep (arg);
- return 1;
- }
-
- dir[0] = 0;
+ dirCount = 0;
/* check for options anywhere in command line */
for (i = 0; i < args; i++)
@@ -596,76 +584,61 @@
}
else
{
- /* get the folder name */
- _tcscpy(dir,arg[i]);
- }
- }
-
- if (dir[0] == _T('\0'))
+ dirCount++;
+ }
+ }
+
+ if (dirCount == 0)
{
/* No folder to remove */
- ConErrResPuts(STRING_ERROR_REQ_PARAM_MISSING);
+ error_req_param_missing();
freep(arg);
return 1;
}
- GetFullPathName(dir,MAX_PATH,szFullPath,NULL);
-
- /* remove trailing \ if any, but ONLY if dir is not the root dir */
- if (_tcslen (szFullPath) >= 2 && szFullPath[_tcslen (szFullPath) - 1] ==
_T('\\'))
- szFullPath[_tcslen(szFullPath) - 1] = _T('\0');
-
- if(RD_SUB)
- {
- /* ask if they want to delete evrything in the folder */
- if (!RD_QUIET)
- {
- res = FilePromptYNA (STRING_DEL_HELP2);
- if ((res == PROMPT_NO) || (res == PROMPT_BREAK))
+ for (i = 0; i < args; i++)
+ {
+ if (*arg[i] == _T('/'))
+ continue;
+
+ if (RD_SUB)
+ {
+ /* ask if they want to delete evrything in the folder */
+ if (!RD_QUIET)
{
- freep(arg);
- nErrorLevel = 1;
- return 1;
+ res = FilePromptYNA (STRING_DEL_HELP2);
+ if (res == PROMPT_NO || res == PROMPT_BREAK)
+ {
+ nError = 1;
+ continue;
+ }
+ if (res == PROMPT_ALL)
+ RD_QUIET = TRUE;
}
- }
-
- }
- else
- {
- /* check for files in the folder */
- _tcscat(szFullPath,_T("\\*"));
-
- hFile = FindFirstFile(szFullPath, &f);
- if (hFile != INVALID_HANDLE_VALUE)
- {
- do
- {
- if (!_tcscmp(f.cFileName,_T(".")) ||
- !_tcscmp(f.cFileName,_T("..")))
- continue;
- ConOutResPuts(STRING_RMDIR_HELP2);
- freep(arg);
- FindClose (hFile);
- nErrorLevel = 1;
- return 1;
- } while (FindNextFile (hFile, &f));
- FindClose (hFile);
- }
- /* reovme the \\* */
- szFullPath[_tcslen(szFullPath) - 2] = _T('\0');
- }
-
- if (!DeleteFolder(szFullPath))
- {
- /* Couldnt delete the folder, clean up and print out the error */
- ErrorMessage (GetLastError(), _T("RD"));
- freep (arg);
- nErrorLevel = 1;
- return 1;
+ /* get the folder name */
+ GetFullPathName(arg[i],MAX_PATH,szFullPath,NULL);
+
+ /* remove trailing \ if any, but ONLY if dir is not the root dir */
+ if (_tcslen (szFullPath) >= 2 && szFullPath[_tcslen (szFullPath) - 1] ==
_T('\\'))
+ szFullPath[_tcslen(szFullPath) - 1] = _T('\0');
+
+ res = DeleteFolder(szFullPath);
+ }
+ else
+ {
+ res = RemoveDirectory(arg[i]);
+ }
+
+ if (!res)
+ {
+ /* Couldn't delete the folder, print out the error */
+ nError = GetLastError();
+ ErrorMessage(nError, _T("RD"));
+ }
}
freep (arg);
- return 0;
+ return nError;
}
#endif