From f53d57c8549dc439eb73354bfd37acd1e4e86cfd Mon Sep 17 00:00:00 2001 From: Jason Edmeades Date: Sun, 24 Jun 2018 21:44:10 +0100 Subject: [PATCH] cmd: Add support for wildcards in if exist. Signed-off-by: Jason Edmeades Signed-off-by: Alexandre Julliard --- programs/cmd/builtins.c | 7 ++++-- programs/cmd/tests/test_builtins.cmd | 43 ++++++++++++++++++++++++++++++++ programs/cmd/tests/test_builtins.cmd.exp | 8 ++++++ 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index 04b098e98db..9fc7502163f 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -2804,8 +2804,11 @@ void WCMD_if (WCHAR *p, CMD_LIST **cmdList) WCMD_parameter(p, 2+negate, &command, FALSE, FALSE); } else if (!lstrcmpiW (condition, existW)) { - test = (GetFileAttributesW(WCMD_parameter(p, 1+negate, NULL, FALSE, FALSE)) - != INVALID_FILE_ATTRIBUTES); + WIN32_FIND_DATAW fd; + HANDLE hff = FindFirstFileW(WCMD_parameter(p, 1+negate, NULL, FALSE, FALSE), &fd); + test = (hff != INVALID_HANDLE_VALUE ); + if (!test) FindClose(hff); + WCMD_parameter(p, 2+negate, &command, FALSE, FALSE); } else if (!lstrcmpiW (condition, defdW)) { diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd index 63ec3cacb1d..d6edc5fff1c 100644 --- a/programs/cmd/tests/test_builtins.cmd +++ b/programs/cmd/tests/test_builtins.cmd @@ -979,6 +979,49 @@ for %%i in (%WINE_STR_PARMS%) do ( for %%i in (%WINE_STR_PARMS%) do ( for %%j in (%WINE_STR_PARMS%) do ( call :GTRtest %%i %%j)) + +echo ------------ Testing if/exist ------------ +mkdir subdir +echo something>subdir\bar +echo something else>foo +if exist foo ( + echo exist explicit works +) else ( + echo ERROR exist explicit broken +) +if exist bar ( + echo ERROR exist explicit unknown file broken +) else ( + echo exist explicit unknown file works +) +if exist subdir\bar ( + echo exist explicit in subdir works +) else ( + echo ERROR exist explicit in subdir broken +) +if exist fo* ( + echo exist simple wildcard works +) else ( + echo ERROR exist simple wildcard broken +) +if exist subdir\ba* ( + echo exist wildcard works +) else ( + echo ERROR exist wildcard broken +) +if not exist subdir\ba* ( + echo ERROR negate exist wildcard broken +) else ( + echo negate exist wildcard works +) +if exist idontexist\ba* ( + echo ERROR exist wildcard bad subdir broken +) else ( + echo exist wildcard bad subdir broken works +) +del foo subdir\bar +rd subdir + echo ------ for numbers if -1 LSS 1 (echo negative numbers handled) if not -1 LSS -10 (echo negative numbers handled) diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp index dcc96299b9e..22d83c3b192 100644 --- a/programs/cmd/tests/test_builtins.cmd.exp +++ b/programs/cmd/tests/test_builtins.cmd.exp @@ -768,6 +768,14 @@ BA GTR B BA GTR AB BA GTR AA AA GTR A +------------ Testing if/exist ------------ +exist explicit works +exist explicit unknown file works +exist explicit in subdir works +exist simple wildcard works +exist wildcard works +negate exist wildcard works +exist wildcard bad subdir broken works ------ for numbers negative numbers handled negative numbers handled -- 2.11.4.GIT