waldgnarf
Goto Top

Letzte Zeile entfernen

Hallöchen, ich habe ein Batch/VBS Programm gebastelt was Infos in MsgBox anzeigt, speichert und löscht.
Es fehlt nur noch ein Batch snipp zum löschen der letzten 2 Zeilen.
Der den ich unten etwas gekennzeichnet habe löscht alle Doppelpunkte und dann hat das Progg keine goto Ziele mer.
set zeile=0
for /f "tokens=1 delims=" %%a in (INFO.txt) do (  
set /a zeile=!zeile!+1
)
for /f "tokens=1 delims=" %%a in (INFO.txt) do (  
if !zeile! gtr 2 echo %%a>>INFOtmp01.txt
set /a zeile=!zeile!-1
)
Und dieser macht, wenn sich die Datei wegen Aktualisierung aus einer Kopie reproduziert, aus den Ausrufezeichen Zahlen von 60-69.^^

@echo off & setlocal enableDelayedExpansion
goto :START
:SPEODERLOE
echo WScript.Echo inputBox("Speichern = s oder Loeschen = l", "AENDERUNGEN")>"soltmp.vbs"  
for /f "delims=" %%i in ('cscript //nologo "soltmp.vbs"') do set sol=%%i  
del "soltmp.vbs"  
if "%sol%"=="s" goto :SPEICHERN  
if "%sol%"=="S" goto :SPEICHERN  
if "%sol%"=="l" goto :LOESCHEN  
if "%sol%"=="L" goto :LOESCHEN  
if "%sol%"=="" exit  
:SPEICHERN
echo WScript.Echo inputBox("keine Sonderzeichen und Zahlen", "TEXT SPEICHERN", "Eingabe")>"spetmp.vbs"  
for /f "delims=" %%i in ('cscript //nologo "spetmp.vbs"') do set spe=%%i  
if not "%spe%"=="" echo "%spe%">"speichern.txt"  
for /f "delims=" %%I in (speichern.txt) do set "X=%%I" & echo !X:~1,-1!>>"speichern.txt"  
del "spetmp.vbs"  
copy "INFO.bat" "INFO.txt"  
:SPEINFO
:-----------------------löscht alle -->":" Zeichen------------------------ 
for /f "delims=:" %%i in ('findstr /n $ "INFO.txt"') do set enfzeile=%%i  
for /f "tokens=1* delims=:" %%i in ('findstr /n $ "INFO.txt"') do if %%i neq %enfzeile% echo.%%j>>"INFOtmp01.txt"  
:-----------------------löscht alle -->":" Zeichen------------------------ 
del "INFO.txt" && ren "INFOtmp01.txt" "INFO.txt"  
:SPEICHERVORGANG
set filter=speichern.txt
set bytes=0
for /R %pfad% %%f in (%filter%) do (
    echo %%f - %%~zfBytes
    set /A bytes=bytes+%%~zf
)
if "%bytes%"=="0" goto :KBSPEENDE  
for /f "delims=" %%A in (speichern.txt) do set spelz=%%A  
echo echo MsgBox "%spelz%"^>^%spelz%msg.vbs>>"INFO.txt"  
echo call "%spelz%msg.vbs">>"INFO.txt"  
type speichern.txt|find /v "%spelz%">spetmp01.txt && move /y spetmp01.txt  
type spetmp01.txt|find /v " ">spetmp02.txt && move /y spetmp02.txt  
for /f %%I in ('dir /b spetmp02.txt') do findstr . %%I>>"spetmp03.txt"  
del "speichern.txt"  
ren "spetmp03.txt" "speichern.txt"  
del "spetmp0*.txt"  
goto :SPEICHERVORGANG
:KBSPEENDE
del "speichern.txt"  
echo del "*msg.vbs">>"INFO.txt"  
echo goto :SPEODERLOE>>"INFO.txt"  
exit
:LOESCHEN
echo WScript.Echo inputBox("keine Sonderzeichen und Zahlen", "TEXT LOESCHEN", "Eingabe")>"loetmp.vbs"  
for /f "delims=" %%i in ('cscript //nologo "loetmp.vbs"') do set loe=%%i  
if not "%loe%"=="" echo "%loe%">"loeschen.txt"  
for /f "delims=" %%I in (loeschen.txt) do set "X=%%I" & echo !X:~1,-1!>>"loeschen.txt"  
del "loetmp.vbs"  
copy "INFO.bat" "INFO.txt"  
:LOESCHVORGANG
set filter=loeschen.txt
set bytes=0
for /R %pfad% %%f in (%filter%) do (
    echo %%f - %%~zfBytes
    set /A bytes=bytes+%%~zf
)
if "%bytes%"=="0" goto :KBLOEENDE  
for /f "delims=" %%A in (loeschen.txt) do set loelz=%%A  
type INFO.txt|find /v "%loelz%.vbs">"INFOtmp.txt"  
del "INFO.txt"  
ren "INFOtmp.txt" "INFO.txt"  
type loeschen.txt|find /v "%loelz%">loetmp01.txt && move /y loetmp01.txt  
type loetmp01.txt|find /v " ">loetmp02.txt && move /y loetmp02.txt  
for /f %%I in ('dir /b loetmp02.txt') do findstr . %%I>>"loetmp03.txt"  
del "loeschen.txt"  
ren "loetmp03.txt" "loeschen.txt"  
del "loetmp0*.txt"  
goto :LOESCHVORGANG
:KBLOEENDE
del "loeschen.txt"  
exit
:START
echo MsgBox "Tachchen">Tachchenmsg.vbs  
call "Tachchenmsg.vbs"  
del "*msg.vbs"  
goto :SPEODERLOE

Grüsse waldgnarf

Content-Key: 89390

Url: https://administrator.de/contentid/89390

Printed on: April 20, 2024 at 04:04 o'clock

Member: bastla
bastla Jun 08, 2008 at 18:56:38 (UTC)
Goto Top
Hallo waldgnarf!

Da Du ja schon mit VBScript arbeitest, könntest Du das so machen:
set R=%temp%\RemoveLastLine.vbs
echo F=WScript.Arguments(0):Set fso=CreateObject("Scripting.FileSystemObject"):T=Split(fso.OpenTextFile(F).ReadAll,vbCrLF):C=(T(UBound(T))=""):U=UBound(T)+C-1:ReDim Preserve T(U):A=Join(T,vbCrLF)^&String(-C,vbCrLF):fso.CreateTextFile(F,True).Write A>%R%  
cscript //nologo %R% "INFO.txt"  
Die Anzahl der zu entfernenden Zeilen steht unmittelbar vor ":ReDim...".

Grüße
bastla
Member: waldgnarf
waldgnarf Jun 08, 2008 at 21:29:32 (UTC)
Goto Top
Danke sehr für deine Hilfe, klappt jetzt alles wie ich es wollte.

Grüße
waldgnarf