In tip 8150, I scripted StripString.bat to remove the last N characters of a string. In tip 4574, I scripted Tail.bat to count the number of lines in a file.

Using those techniques, I have scripted StripFile.bat to remove the last N characters of the last line of a file.

The syntax for using StripFile.bat is:

StripFile FileName \[NumChar\]

Where FileName is the file you wish to shorten, and NumChar is an optional parameter that contains the number of characters (N) to remove. The default is 1.

StripFile.bat contains:

@echo off
if \{%1\}<h1><a name="_echo_Syntax_StripFile_FileName_NumChar_amp_goto_EOF_if_not_exist_1_echo_StripFile_File_1_not_found_amp_goto_EOF_setlocal_ENABLEDELAYEDEXPANSION_set_wrk_TEMP_StripFile_tmp_set_fle_1_set_a_strip_1_if_not_2_">\{\}  @echo Syntax: StripFile FileName \[NumChar\]&goto :EOF
if not exist %1 @echo StripFile File %1 not found.&goto :EOF
set wrk="%TEMP%\StripFile.tmp"
set fle=%1
set /a strip=1
if not \{%2\}</a></h1>\{\} set /a strip=%2
if exist %wrk% del /q %wrk%
for /f %%n in ('find /V /C "" ^>%wrk%
 ) else (
    set rec=%%L
    call set out=!rec:~0,^-%strip%!
call :cpy >nul 2>&1
del /q %wrk%
goto :EOF
copy /Y %wrk% %fle%