Question: The path to the folder and the format come to the input of the batch file 
file(for example, txt) (as parameters of a batch file). 
The folder must contain different files. 
If such folder does not exist, then write “This folder does not exist” and 
terminate the program. 
If such a folder exists, then find everything in it and in its subfolders 
files of the specified extension for which it is installed 
archive attribute. Output the number of such files in 
console

**[Edit /]**

This is what I have:

```
@echo off
if not exist %1 (echo "This folder does not exist" && pause && exit /B )
set /a count=0
for %%i in (dir %1\*.%2 /A:A /S ) do ( set /a count+=1 )
Echo in the folder %1, found %count% files with extension %2 and attribute 
Archive
pause

```

The final count is incorrect
[![enter image description here](https://i.stack.imgur.com/izyaN.png)](https://i.stack.imgur.com/izyaN.png)

Answer: 
You solution is just fine.

A less expressive way would be to wrap your code to be timed in a lambda.

```
public void timeCode(Runnable code) {
    ...
    try {
        code.run();
    } catch ...
    }
    ...
}

timeCode(() -> { ...code to time... });

```

You would probably like to catch the checked exceptions and pass them to some runtime exception or whatever.
I think the solution that is suggested in the question text is **too indirect and non-idiomatic** to be suitable for production code. (But it looks like a neat tool to get quick timings of stuff during development.)

Both the [Guava project](https://google.github.io/guava/releases/18.0/api/docs/com/google/common/base/Stopwatch.html) and the [Apache Commons](https://commons.apache.org/proper/commons-lang/javadocs/api-3.1/index.html?org/apache/commons/lang3/time/StopWatch.html) include **stop-watch classes**. If you use any of them the code will be easier to read and understand, and these classes have more built-in functionality too.

Even without using a try-with-resource statement the section that is being measured can be **enclosed in a block** to improve clarity:

```
// Do things that shouldn't be measured

{
    Stopwatch watch = Stopwatch.createStarted();

    // Do things that should be measured

    System.out.println("Duration: " + watch.elapsed(TimeUnit.SECONDS) + " s");
}

```