I'm trying to create a batch file using IF EXIST that searches for a specified file. The sub directory name changes everyday. If the sub directory name is hard coded then it works. I tried using a wild card for the sub directory and it doesn't work. Is it possible to use wild cards in this situation?
The temp2 directories are named like this:
temp2_11-20-09
temp2_11-21-09
temp2_11-22-09
temp2_11-23-09
temp2_11-24-09
@echo off
IF EXIST c:\temp\temp2*\test.txt (
echo "File exists"
) ELSE (
echo "file does not exist"
)
IF EXIST with wildcards
Moderator: DosItHelp
-
- Expert
- Posts: 391
- Joined: 19 Mar 2009 08:47
- Location: Iowa
Don't think that'll work -- I'd use a for loop:
Code: Select all
@echo off
cd /d c:\temp
for /d %%a in (temp2*) do (
if exist "%%a\test.txt" echo File exists.&&goto continue
)
echo File does not exist.
:continue
echo Rest of your code here.
Thanks Larry...
I was wondering, the file I'm searching for is on a network drive so instead of using cd to change to the directory can I do something like this:
@echo off
for /d %%a in (temp2*) do (
IF EXIST "\\10.10.10.20\marketing\logs\%%a\test.txt" echo "File exist" && goto continue
)
echo File does not exist
:continue
echo Rest of your code here
I was wondering, the file I'm searching for is on a network drive so instead of using cd to change to the directory can I do something like this:
@echo off
for /d %%a in (temp2*) do (
IF EXIST "\\10.10.10.20\marketing\logs\%%a\test.txt" echo "File exist" && goto continue
)
echo File does not exist
:continue
echo Rest of your code here