none
Test for existence of file with a wildcard? RRS feed

  • Question

  • Without using PowerShell, is there a way to test for the existence of a file using wildcards?

    I know of the "EXISTS" command in DOS, but it doesn't seem to work with wildcards.

    Help, please?

    Thanks.

    Monday, February 24, 2014 1:49 PM

Answers

  • Can you try it with the "dir command"? If found, the errorlevel (%ERRORLEVEL%) will be 0 - if not found, it will be 1 (or other not equal 0).


    • Edited by Peter Ziganki Monday, February 24, 2014 2:35 PM
    • Proposed as answer by Mike Laughlin Monday, February 24, 2014 3:54 PM
    • Marked as answer by Dougmeister2 Monday, February 24, 2014 4:19 PM
    Monday, February 24, 2014 2:34 PM
  • Without using PowerShell, is there a way to test for the existence of a file using wildcards?

    I know of the "EXISTS" command in DOS, but it doesn't seem to work with wildcards.

    Help, please?

    Thanks.

    Here you go:

    dir "d:\My Files\abc*.xls"
    if %ErrorLevel% EQU 0 (echo Found!) else (echo Not found . . .)

    Note also that DOS disappeared some 14 years ago with Windows ME. You're probably thinking of Console commands.


    • Edited by Frederik Long Monday, February 24, 2014 3:19 PM
    • Proposed as answer by Mike Laughlin Monday, February 24, 2014 3:54 PM
    • Marked as answer by Dougmeister2 Monday, February 24, 2014 4:19 PM
    Monday, February 24, 2014 2:51 PM

All replies