Bestimmte Zeilen einer Textdatei automatisch löschen
Hallo,
Ich möchte in einem Programm, das Einträge in eine TXT schreibt, immer nur eine bestimmte Anzahl an Einträgen haben. Also dass die alten automatisch gelöscht werden.
Kann mir bitte jemand sagen, wie das geht?
MfG
Ich möchte in einem Programm, das Einträge in eine TXT schreibt, immer nur eine bestimmte Anzahl an Einträgen haben. Also dass die alten automatisch gelöscht werden.
Kann mir bitte jemand sagen, wie das geht?
MfG
Please also mark the comments that contributed to the solution of the article
Content-Key: 396837
Url: https://administrator.de/contentid/396837
Printed on: April 19, 2024 at 11:04 o'clock
6 Comments
Latest comment
@echo off &setlocal
set /a "max=10"
set "file=test.txt"
for /l %%i in () do (
set "line="
set /p "line=Neue Zeile: "
call :write
)
exit /b
:write
setlocal EnableDelayedExpansion
if not exist "!file!" >"!file!" type nul
for /f %%i in ('type "!file!"^|find /c /v ""') do set /a "skip=%%i + 1 - max"
if %skip% gtr 0 (
<"!file!" >"!file!.~tmp" more +%skip%
>nul move /y "!file!.~tmp" "!file!"
)
>>"!file!" echo(!line!
endlocal
exit /b
@echo off &setlocal
set /a "max=10"
set "file=message.txt"
for /l %%i in () do (
cls
echo Nachricht eingeben:
echo -------------------
echo(
set "message="
set /p "message="
call :write
)
exit /b
:write
setlocal EnableDelayedExpansion
if not exist "!file!" >"!file!" type nul
for /f %%i in ('type "!file!"^|find /c /v ""') do set /a "skip=%%i + 1 - max"
if %skip% gtr 0 (
<"!file!" >"!file!.~tmp" more +%skip%
>nul move /y "!file!.~tmp" "!file!"
)
>>"!file!" echo(!username!, !time!: !message!
endlocal
exit /b