mirror of
https://github.com/reactos/reactos.git
synced 2025-07-23 08:24:01 +00:00
[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.
This commit is contained in:
parent
9a59558307
commit
f79d268ea1
1 changed files with 25 additions and 17 deletions
|
@ -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);
|
||||
|
||||
/* strip the filename off of it */
|
||||
pFilePart = _tcsrchr(szFullPath, _T('\\'));
|
||||
if (pFilePart == NULL)
|
||||
pSearchPart = _T("*");
|
||||
if (!IsExistingDirectory(szFullPath))
|
||||
{
|
||||
pFilePart = szFullPath;
|
||||
pSearchPart = _tcsrchr(FileName, _T('\\'));
|
||||
if (pSearchPart != NULL)
|
||||
pSearchPart++;
|
||||
else
|
||||
pSearchPart = FileName;
|
||||
}
|
||||
|
||||
/* 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[_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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue