cmd_rmdir: Implement ability to remove multiple directories with one command.

svn path=/trunk/; revision=38946
This commit is contained in:
Jeffrey Morlan 2009-01-19 17:29:21 +00:00
parent f601277c56
commit fd6ed40845

View file

@ -542,16 +542,15 @@ BOOL DeleteFolder(LPTSTR FileName)
} }
INT cmd_rmdir (LPTSTR param) INT cmd_rmdir (LPTSTR param)
{ {
TCHAR dir[MAX_PATH]; /* pointer to the directory to change to */
TCHAR ch; TCHAR ch;
INT args; INT args;
LPTSTR *arg = NULL; INT dirCount;
LPTSTR *arg;
INT i; INT i;
BOOL RD_SUB = FALSE; BOOL RD_SUB = FALSE;
BOOL RD_QUIET = FALSE; BOOL RD_QUIET = FALSE;
HANDLE hFile;
WIN32_FIND_DATA f;
INT res; INT res;
INT nError = 0;
TCHAR szFullPath[MAX_PATH]; TCHAR szFullPath[MAX_PATH];
if (!_tcsncmp (param, _T("/?"), 2)) if (!_tcsncmp (param, _T("/?"), 2))
@ -560,19 +559,8 @@ INT cmd_rmdir (LPTSTR param)
return 0; return 0;
} }
nErrorLevel = 0;
arg = split (param, &args, FALSE); arg = split (param, &args, FALSE);
dirCount = 0;
if (args == 0)
{
/* only command given */
error_req_param_missing ();
freep (arg);
return 1;
}
dir[0] = 0;
/* check for options anywhere in command line */ /* check for options anywhere in command line */
for (i = 0; i < args; i++) for (i = 0; i < args; i++)
@ -596,24 +584,22 @@ INT cmd_rmdir (LPTSTR param)
} }
else else
{ {
/* get the folder name */ dirCount++;
_tcscpy(dir,arg[i]);
} }
} }
if (dir[0] == _T('\0')) if (dirCount == 0)
{ {
/* No folder to remove */ /* No folder to remove */
ConErrResPuts(STRING_ERROR_REQ_PARAM_MISSING); error_req_param_missing();
freep(arg); freep(arg);
return 1; return 1;
} }
GetFullPathName(dir,MAX_PATH,szFullPath,NULL); for (i = 0; i < args; i++)
{
/* remove trailing \ if any, but ONLY if dir is not the root dir */ if (*arg[i] == _T('/'))
if (_tcslen (szFullPath) >= 2 && szFullPath[_tcslen (szFullPath) - 1] == _T('\\')) continue;
szFullPath[_tcslen(szFullPath) - 1] = _T('\0');
if (RD_SUB) if (RD_SUB)
{ {
@ -621,51 +607,38 @@ INT cmd_rmdir (LPTSTR param)
if (!RD_QUIET) if (!RD_QUIET)
{ {
res = FilePromptYNA (STRING_DEL_HELP2); res = FilePromptYNA (STRING_DEL_HELP2);
if ((res == PROMPT_NO) || (res == PROMPT_BREAK)) if (res == PROMPT_NO || res == PROMPT_BREAK)
{ {
freep(arg); nError = 1;
nErrorLevel = 1; continue;
return 1;
} }
if (res == PROMPT_ALL)
RD_QUIET = TRUE;
} }
/* 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 else
{ {
/* check for files in the folder */ res = RemoveDirectory(arg[i]);
_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)) if (!res)
{ {
/* Couldnt delete the folder, clean up and print out the error */ /* Couldn't delete the folder, print out the error */
ErrorMessage (GetLastError(), _T("RD")); nError = GetLastError();
freep (arg); ErrorMessage(nError, _T("RD"));
nErrorLevel = 1; }
return 1;
} }
freep (arg); freep (arg);
return 0; return nError;
} }
#endif #endif