0

The title is pretty much self explanatory and my example makes it pretty obvious but I'm trying to find for a particular exe file and execute it.

cd c:\

for /f %%f in ('dir /b /s eclipse.exe') do (
    start %%f -clean
)

echo Done!  
pause >nul

For safety reason please let me know if it's possible to run only the first file found or look for a particular hash string or file size.

Thanks !

Steven
  • 249
  • 5
  • 14

1 Answers1

0

To run only the first file found ("tokens=*" to eliminate spaces in path(s); note also required empty string "" in start "" "%%f" -clean)

for /f "tokens=*" %%f in ('dir /b /s eclipse.exe') do (
    start "" "%%f" -clean
    goto :enough
)
:enough
echo Done

To look for file size

for /f "tokens=*" %%f in ('dir /b /s eclipse.exe') do (
   for /F "tokens=3" %%H in ('dir "%%f"^|find /I "%%~nxf"') do (
      @echo %%f size=%%H
   )
)

To look for a particular hash string: in cmd line need an external tool like File Checksum Integrity Verifier (FCIV) or better HashMyFiles etc.

In Windows PowerShell: Get-FileHash computes the hash value for a file by using a specified hash algorithm.

JosefZ
  • 28,460
  • 5
  • 44
  • 83