@echo off setlocal EnableExtensions if "%~1"=="" goto usage if "%~2"=="" goto usage if /i "%~1"=="%~2" ( echo Input and output must be different. exit /b 1 ) if not exist "%~1" ( echo Input file not found: %~1 exit /b 1 ) if exist "%~2" if /i not "%~3"=="/y" ( echo Output file exists: %~2 echo Add /y to overwrite it. exit /b 1 ) findstr /n "^" "%~1" > "%~2" if not exist "%~2" ( echo Failed to write output. exit /b 1 ) echo Numbered lines written to %~2 exit /b 0 :usage echo Usage: number_lines.bat input.txt output.txt [/y] exit /b 2