Question

How can i find that *.err file type exist or not in batch file. I am using the following code to find the existence of the file type.

if [ -f $"*.err" ]
then
   echo "File Type exists"
else
   echo "File Type does not exists"
fi

I think this code is not accurate. Can you correct this to find the existence of the file type ?

Was it helpful?

Solution

In batch File the Script Looks like this:

@Echo off

Rem DistPath Is Where you Want to check for file type
Set "DistPath=%UserProfile%\Desktop"
If Exist "%DistPath%\*.err" ( Echo File Type exists
) Else (
      Echo File Type does not exists
)
pause

Edit:

Try This & Add The code that need to be executed between the "ExecuteFlag" & "Goto EOF".

@Echo off

If Exist "*.err" ( 
    Goto EOF
) Else (
    Goto ExecuteFlag
)
pause
Exit

Rem Put Your Code Down Here
:ExecuteFlag
<<< Your Code Here >>>

Goto EOF

But in case you will continue & Add a lot more than few lines this is better

If Exist "*.err" Goto :EOF 

Then Add The rest of your code assuming you didn't find the file. So if the file exist the code will end, else it will handle the missing file type depending on your code

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top