https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f79d268ea1d1cf474ab02…
commit f79d268ea1d1cf474ab02370d2392f66d9a18ebc
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sun Dec 3 16:01:44 2017 +0100
[CMD] Fix the del /s command, reported by Pablo De Napoli. CORE-10460
The command should delete files in the specified directory and all of its
sub-directories, using any file pattern specified.
For example, the command:
del /S .\my_directory
should delete all the files inside my_directory and its sub-directories,
and as such should also detect that "my_directory" is indeed a directory,
while doing:
del /S .\my_file
should of course detect that "my_file" is indeed a file pattern, and thus,
delete all "my_file" files from the current directory and its sub-directories.
The command:
del /S some_directory\file_pattern
should delete "file_pattern" files from some_directory and its sub-directories.
---
base/shell/cmd/del.c | 40 ++++++++++++++++++++++++----------------
1 file changed, 24 insertions(+), 16 deletions(-)
diff --git a/base/shell/cmd/del.c b/base/shell/cmd/del.c
index 5d3d3ca4c0..4c0dc3a876 100644
--- a/base/shell/cmd/del.c
+++ b/base/shell/cmd/del.c
@@ -284,39 +284,46 @@ ProcessDirectory(LPTSTR FileName, DWORD* dwFlags, DWORD dwAttrFlags)
WIN32_FIND_DATA f;
DWORD dwFiles = 0;
+ /* Get the full path to the file */
GetFullPathName(FileName,
MAX_PATH,
szFullPath,
&pFilePart);
+ /* Delete all the files in this directory */
dwFiles = DeleteFiles(szFullPath, dwFlags, dwAttrFlags);
- if (dwFiles & 0x80000000) return dwFiles;
+ if (dwFiles & 0x80000000)
+ return dwFiles;
if (*dwFlags & DEL_SUBDIR)
{
/* Get just the file name */
- pSearchPart = _tcsrchr(FileName,_T('\\'));
- if (pSearchPart != NULL)
- pSearchPart++;
- else
- pSearchPart = FileName;
-
- /* Get the full path to the file */
- GetFullPathName (FileName,MAX_PATH,szFullPath,NULL);
+ pSearchPart = _T("*");
+ if (!IsExistingDirectory(szFullPath))
+ {
+ pSearchPart = _tcsrchr(FileName, _T('\\'));
+ if (pSearchPart != NULL)
+ pSearchPart++;
+ else
+ pSearchPart = FileName;
+ }
- /* strip the filename off of it */
- pFilePart = _tcsrchr(szFullPath, _T('\\'));
- if (pFilePart == NULL)
+ /* If no wildcard or file was specified and this is a directory, then
+ display all files in it */
+ if (pFilePart == NULL || IsExistingDirectory(szFullPath))
{
- pFilePart = szFullPath;
+ pFilePart = &szFullPath[_tcslen(szFullPath)];
+ if (*(pFilePart-1) != _T('\\'))
+ *pFilePart++ = _T('\\');
+ _tcscpy(pFilePart, _T("*"));
}
else
{
- pFilePart++;
+ /* strip the filename off of it */
+ _tcscpy(pFilePart, _T("*"));
}
- _tcscpy(pFilePart, _T("*"));
-
+ /* Enumerate all the sub-directories */
hFile = FindFirstFile(szFullPath, &f);
if (hFile != INVALID_HANDLE_VALUE)
{
@@ -341,6 +348,7 @@ ProcessDirectory(LPTSTR FileName, DWORD* dwFlags, DWORD dwAttrFlags)
FindClose (hFile);
}
}
+
return dwFiles;
}