mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 06:25:49 +00:00
[CMD]
Fix and simplify implementation of "IF EXIST": - Don't make any difference between wildcard search and normal search - This fixes handling DOS devices search (ie, IF EXIST C:\ReactOS\NUL now works) - This fixes handling pagefile.sys without requiring specifing rights - Also fix handling directory search, terminated with a \ CORE-11784 svn path=/trunk/; revision=74444
This commit is contained in:
parent
3e2f6b9d2c
commit
dd512f56a9
1 changed files with 22 additions and 9 deletions
|
@ -114,23 +114,36 @@ INT ExecuteIf(PARSED_COMMAND *Cmd)
|
||||||
}
|
}
|
||||||
else if (Cmd->If.Operator == IF_EXIST)
|
else if (Cmd->If.Operator == IF_EXIST)
|
||||||
{
|
{
|
||||||
|
BOOL IsDir;
|
||||||
|
INT Size;
|
||||||
|
WIN32_FIND_DATA f;
|
||||||
|
HANDLE hFind;
|
||||||
|
|
||||||
/* IF EXIST filename: check if file exists (wildcards allowed) */
|
/* IF EXIST filename: check if file exists (wildcards allowed) */
|
||||||
StripQuotes(Right);
|
StripQuotes(Right);
|
||||||
|
|
||||||
if (_tcschr(Right, _T('*')) || _tcschr(Right, _T('?')))
|
Size = _tcslen(Right);
|
||||||
{
|
IsDir = (Right[Size - 1] == '\\');
|
||||||
WIN32_FIND_DATA f;
|
if (IsDir)
|
||||||
HANDLE hFind = FindFirstFile(Right, &f);
|
Right[Size - 1] = 0;
|
||||||
|
|
||||||
|
|
||||||
|
hFind = FindFirstFile(Right, &f);
|
||||||
if (hFind != INVALID_HANDLE_VALUE)
|
if (hFind != INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
result = TRUE;
|
if (IsDir)
|
||||||
FindClose(hFind);
|
{
|
||||||
}
|
result = ((f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = (GetFileAttributes(Right) != INVALID_FILE_ATTRIBUTES);
|
result = TRUE;
|
||||||
}
|
}
|
||||||
|
FindClose(hFind);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsDir)
|
||||||
|
Right[Size - 1] = '\\';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue