Author: pschweitzer
Date: Mon May 1 21:14:38 2017
New Revision: 74444
URL:
http://svn.reactos.org/svn/reactos?rev=74444&view=rev
Log:
[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
Modified:
trunk/reactos/base/shell/cmd/if.c
Modified: trunk/reactos/base/shell/cmd/if.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/if.c?rev=74…
==============================================================================
--- trunk/reactos/base/shell/cmd/if.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/if.c [iso-8859-1] Mon May 1 21:14:38 2017
@@ -114,23 +114,36 @@
}
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) */
StripQuotes(Right);
- if (_tcschr(Right, _T('*')) || _tcschr(Right, _T('?')))
+ Size = _tcslen(Right);
+ IsDir = (Right[Size - 1] == '\\');
+ if (IsDir)
+ Right[Size - 1] = 0;
+
+
+ hFind = FindFirstFile(Right, &f);
+ if (hFind != INVALID_HANDLE_VALUE)
{
- WIN32_FIND_DATA f;
- HANDLE hFind = FindFirstFile(Right, &f);
- if (hFind != INVALID_HANDLE_VALUE)
+ if (IsDir)
+ {
+ result = ((f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ==
FILE_ATTRIBUTE_DIRECTORY);
+ }
+ else
{
result = TRUE;
- FindClose(hFind);
}
+ FindClose(hFind);
}
- else
- {
- result = (GetFileAttributes(Right) != INVALID_FILE_ATTRIBUTES);
- }
+
+ if (IsDir)
+ Right[Size - 1] = '\\';
}
else
{