"if exist" with wildcards in path?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
pstein
Posts: 125
Joined: 09 Nov 2011 01:42

"if exist" with wildcards in path?

#1 Post by pstein » 30 Jan 2016 02:36

If I execute the following command (with wildcard in path) in a DOS batch file then the result is not found:

if exist "D:\archive\logs\log*2015\*.zip" ( Echo found)

although such files as

D:\archive\logs\log 04.2015\test.zip

exist!. If I omit the wildcard in the path and just leave the wildcard in filename then it works:

if exist "D:\archive\logs\log 04.2015\*.zip" ( Echo found)

Is this correct?
Is there no way to put wildcards in pathes?

Peter

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: "if exist" with wildcards in path?

#2 Post by foxidrive » 30 Jan 2016 04:46

Wildcards in paths aren't supported in the if exist command.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: "if exist" with wildcards in path?

#3 Post by aGerman » 30 Jan 2016 08:18

To be more clear - in general wildcards are only supported in the last element of the entire path.

Code: Select all

for /d %%i in ("D:\archive\logs\log*2015") do if exist "%%~i\*.zip" echo found

Regards
aGerman

Post Reply