mirror of
https://github.com/reactos/reactos.git
synced 2025-05-23 19:14:48 +00:00
Brandon Turner <turnerb7@msu.edu> Added exclusive deletion "del * -abc.txt -text*.txt"
svn path=/trunk/; revision=16215
This commit is contained in:
parent
164b25c391
commit
73abbbd77e
2 changed files with 68 additions and 12 deletions
|
@ -32,6 +32,9 @@
|
||||||
*
|
*
|
||||||
* 28-Jan-2004 (Michael Fritscher <michael@fritscher.net>)
|
* 28-Jan-2004 (Michael Fritscher <michael@fritscher.net>)
|
||||||
* Added prompt ("/P"), yes ("/Y") and wipe("/W") option.
|
* Added prompt ("/P"), yes ("/Y") and wipe("/W") option.
|
||||||
|
*
|
||||||
|
* 22-Jun-2005 (Brandon Turner <turnerb7@msu.edu>)
|
||||||
|
* Added exclusive deletion "del * -abc.txt -text*.txt"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "precomp.h"
|
#include "precomp.h"
|
||||||
|
@ -60,6 +63,10 @@ enum
|
||||||
static BOOL
|
static BOOL
|
||||||
RemoveFile (LPTSTR lpFileName, DWORD dwFlags)
|
RemoveFile (LPTSTR lpFileName, DWORD dwFlags)
|
||||||
{
|
{
|
||||||
|
/*This function is called by CommandDelete and
|
||||||
|
does the actual process of deleting the single
|
||||||
|
file*/
|
||||||
|
|
||||||
if (dwFlags & DEL_WIPE)
|
if (dwFlags & DEL_WIPE)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -92,26 +99,38 @@ RemoveFile (LPTSTR lpFileName, DWORD dwFlags)
|
||||||
ConOutPrintf (_T("100%% %s\n"),szMsg);
|
ConOutPrintf (_T("100%% %s\n"),szMsg);
|
||||||
CloseHandle (file);
|
CloseHandle (file);
|
||||||
}
|
}
|
||||||
|
|
||||||
return DeleteFile (lpFileName);
|
return DeleteFile (lpFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
INT CommandDelete (LPTSTR cmd, LPTSTR param)
|
INT CommandDelete (LPTSTR cmd, LPTSTR param)
|
||||||
{
|
{
|
||||||
|
/*cmd is the command that was given, in this case it will always be "del" or "delete"
|
||||||
|
param is whatever is given after the command*/
|
||||||
|
|
||||||
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
TCHAR szMsg[RC_STRING_MAX_SIZE];
|
||||||
TCHAR szFullPath[MAX_PATH];
|
TCHAR szFullPath[MAX_PATH];
|
||||||
LPTSTR pFilePart;
|
LPTSTR pFilePart;
|
||||||
LPTSTR *arg = NULL;
|
LPTSTR *arg = NULL;
|
||||||
|
TCHAR exfileName[MAX_PATH];
|
||||||
|
TCHAR * szFileName;
|
||||||
INT args;
|
INT args;
|
||||||
INT i;
|
INT i;
|
||||||
|
INT ii;
|
||||||
INT res;
|
INT res;
|
||||||
INT nEvalArgs = 0; /* nunber of evaluated arguments */
|
INT nEvalArgs = 0; /* nunber of evaluated arguments */
|
||||||
DWORD dwFlags = 0;
|
DWORD dwFlags = 0;
|
||||||
DWORD dwFiles = 0;
|
DWORD dwFiles = 0;
|
||||||
HANDLE hFile;
|
HANDLE hFile;
|
||||||
|
HANDLE hFileExcl;
|
||||||
WIN32_FIND_DATA f;
|
WIN32_FIND_DATA f;
|
||||||
|
WIN32_FIND_DATA f2;
|
||||||
LONG ch;
|
LONG ch;
|
||||||
|
BOOL bExclusion;
|
||||||
|
|
||||||
|
/*checks the first two chars of param to see if it is /?
|
||||||
|
this however allows the following command to not show help
|
||||||
|
"del frog.txt /?" */
|
||||||
|
|
||||||
if (!_tcsncmp (param, _T("/?"), 2))
|
if (!_tcsncmp (param, _T("/?"), 2))
|
||||||
{
|
{
|
||||||
|
@ -128,6 +147,7 @@ INT CommandDelete (LPTSTR cmd, LPTSTR param)
|
||||||
{
|
{
|
||||||
if (*arg[i] == _T('/'))
|
if (*arg[i] == _T('/'))
|
||||||
{
|
{
|
||||||
|
/*found a command, but check to make sure it has something after it*/
|
||||||
if (_tcslen (arg[i]) >= 2)
|
if (_tcslen (arg[i]) >= 2)
|
||||||
{
|
{
|
||||||
ch = _totupper (arg[i][1]);
|
ch = _totupper (arg[i][1]);
|
||||||
|
@ -169,7 +189,8 @@ INT CommandDelete (LPTSTR cmd, LPTSTR param)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* there are only options on the command line --> error!!! */
|
/* there are only options on the command line --> error!!!
|
||||||
|
there is the same number of args as there is flags, so none of the args were filenames*/
|
||||||
if (args == nEvalArgs)
|
if (args == nEvalArgs)
|
||||||
{
|
{
|
||||||
error_req_param_missing ();
|
error_req_param_missing ();
|
||||||
|
@ -187,6 +208,9 @@ INT CommandDelete (LPTSTR cmd, LPTSTR param)
|
||||||
if (!_tcscmp (arg[i], _T("*")) ||
|
if (!_tcscmp (arg[i], _T("*")) ||
|
||||||
!_tcscmp (arg[i], _T("*.*")))
|
!_tcscmp (arg[i], _T("*.*")))
|
||||||
{
|
{
|
||||||
|
/*well, the user wants to delete everything but if they didnt yes DEL_YES, DEL_QUIET, or DEL_PROMPT
|
||||||
|
then we are going to want to make sure that in fact they want to do that. */
|
||||||
|
|
||||||
if (!((dwFlags & DEL_YES) || (dwFlags & DEL_QUIET) || (dwFlags & DEL_PROMPT)))
|
if (!((dwFlags & DEL_YES) || (dwFlags & DEL_QUIET) || (dwFlags & DEL_PROMPT)))
|
||||||
{
|
{
|
||||||
LoadString( CMD_ModuleHandle, STRING_DEL_HELP2, szMsg, RC_STRING_MAX_SIZE);
|
LoadString( CMD_ModuleHandle, STRING_DEL_HELP2, szMsg, RC_STRING_MAX_SIZE);
|
||||||
|
@ -196,8 +220,9 @@ INT CommandDelete (LPTSTR cmd, LPTSTR param)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*arg[i] != _T('/'))
|
/*this checks to see if it isnt a flag, if it isnt, we assume it is a file name*/
|
||||||
|
if ((*arg[i] != _T('/')) && (*arg[i] != _T('-')))
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
ConErrPrintf (_T("File: %s\n"), arg[i]);
|
ConErrPrintf (_T("File: %s\n"), arg[i]);
|
||||||
|
@ -209,7 +234,7 @@ INT CommandDelete (LPTSTR cmd, LPTSTR param)
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
ConErrPrintf(_T("Wildcards!\n\n"));
|
ConErrPrintf(_T("Wildcards!\n\n"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
GetFullPathName (arg[i],
|
GetFullPathName (arg[i],
|
||||||
MAX_PATH,
|
MAX_PATH,
|
||||||
szFullPath,
|
szFullPath,
|
||||||
|
@ -230,12 +255,44 @@ INT CommandDelete (LPTSTR cmd, LPTSTR param)
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/*bExclusion is the check varible to see if it has a match
|
||||||
|
and it needs to be set to false before each loop, as it hasnt been matched yet*/
|
||||||
|
bExclusion = 0;
|
||||||
|
|
||||||
|
/*loop through each of the arguments*/
|
||||||
|
for (ii = 0; ii < args; ii++)
|
||||||
|
{
|
||||||
|
/*check to see if it is a exclusion tag*/
|
||||||
|
if(_tcschr (arg[ii], _T('-')))
|
||||||
|
{
|
||||||
|
/*remove the - from the front to get the real name*/
|
||||||
|
_tcscpy (exfileName , arg[ii]);
|
||||||
|
szFileName = strtok (exfileName,"-");
|
||||||
|
GetFullPathName (szFileName,
|
||||||
|
MAX_PATH,
|
||||||
|
szFullPath,
|
||||||
|
&pFilePart);
|
||||||
|
hFileExcl = FindFirstFile (szFullPath, &f2);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
/*check to see if the filenames match*/
|
||||||
|
if(!_tcscmp (f.cFileName, f2.cFileName))
|
||||||
|
bExclusion = 1;
|
||||||
|
}
|
||||||
|
while (FindNextFile (hFileExcl, &f2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!bExclusion)
|
||||||
|
{
|
||||||
/* ignore ".", ".." and directories */
|
/* ignore ".", ".." and directories */
|
||||||
if (!_tcscmp (f.cFileName, _T(".")) ||
|
if (!_tcscmp (f.cFileName, _T(".")) ||
|
||||||
!_tcscmp (f.cFileName, _T("..")) ||
|
!_tcscmp (f.cFileName, _T("..")) ||
|
||||||
f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
_tcscpy (pFilePart, f.cFileName);
|
_tcscpy (pFilePart, f.cFileName);
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
|
@ -256,13 +313,14 @@ INT CommandDelete (LPTSTR cmd, LPTSTR param)
|
||||||
continue; //FIXME: Errorcode?
|
continue; //FIXME: Errorcode?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*user cant ask it to be quiet and tell you what it did*/
|
||||||
if (!(dwFlags & DEL_QUIET) && !(dwFlags & DEL_TOTAL))
|
if (!(dwFlags & DEL_QUIET) && !(dwFlags & DEL_TOTAL))
|
||||||
{
|
{
|
||||||
LoadString(CMD_ModuleHandle, STRING_DEL_ERROR7, szMsg, RC_STRING_MAX_SIZE);
|
LoadString(CMD_ModuleHandle, STRING_DEL_ERROR7, szMsg, RC_STRING_MAX_SIZE);
|
||||||
ConErrPrintf(szMsg, szFullPath);
|
ConErrPrintf(szMsg, szFullPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* delete the file */
|
/* delete the file */
|
||||||
if (!(dwFlags & DEL_NOTHING))
|
if (!(dwFlags & DEL_NOTHING))
|
||||||
{
|
{
|
||||||
|
@ -296,12 +354,14 @@ INT CommandDelete (LPTSTR cmd, LPTSTR param)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while (FindNextFile (hFile, &f));
|
while (FindNextFile (hFile, &f));
|
||||||
FindClose (hFile);
|
FindClose (hFile);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
/* no wildcards in filespec */
|
/* no wildcards in filespec */
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
ConErrPrintf(_T("No Wildcards!\n"));
|
ConErrPrintf(_T("No Wildcards!\n"));
|
||||||
|
@ -395,7 +455,6 @@ INT CommandDelete (LPTSTR cmd, LPTSTR param)
|
||||||
|
|
||||||
ConOutPrintf(szMsg, dwFiles);
|
ConOutPrintf(szMsg, dwFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,6 @@
|
||||||
Wishlist for ReactOS CMD
|
Wishlist for ReactOS CMD
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
- Exclusion wildcards: "del /r *.bak -abcd.bak"
|
|
||||||
Deletes ALL *.bak files EXCEPT abcd.bak.
|
|
||||||
|
|
||||||
- Progress indikator on long file operations (copy/move).
|
- Progress indikator on long file operations (copy/move).
|
||||||
Percentage at the right side of the filename.
|
Percentage at the right side of the filename.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue