Ich möchte eine Batch-Datei erstellen die mir eine datei in zwei teile teilt!
Ist so etwas möglich![]()
Wenn ja welchen befehl muss ich verwenden![]()
Ich möchte eine Batch-Datei erstellen die mir eine datei in zwei teile teilt!
Ist so etwas möglich![]()
Wenn ja welchen befehl muss ich verwenden![]()
Moin Timo, wäre das etwas für Dich? Ist aber speziell nur für Textdateien.
01 ::-----snipp Splitbla.bat Vers. 0.2----
02 @echo off
03 IF (%1)==() (echo Syntax %0 inputfile) & goto :eof
04 if not exist "%1" echo (Datei %1 nicht gefunden) & goto :eof
05 setlocal
06 (set blafile=%1) & (set FirstLine=) & (set LastLine=)
07 for /f "delims=" %%i in ('type bla.txt') do if not defined firstline set firstline=%%i
08 for /f "delims=" %%i in ('type bla.txt') do set lastline=%%i
09 echo %firstline% >%temp%\Headline.Txt
10 :: type %blafile% |find /i "Benutzer" >%temp%\Headline.Txt
11 (set /a cntLn=0 ) && REM Zeilenzähler
12 (set /a MaxLnsPerFile=10) && REM Max. Zeilen je Splitdatei, eigentlich Konstante
13 (set /a FileCnt=1 ) && REM Zähler für die Splitdateien
14 (Set Dirty=TRUE ) && REM DirtyFlag.. muss ich noch eine Datei "endgültig" schreiben?
15 if exist %temp%\tmpbla*.tmp del /q %temp%\tmpbla-*.tmp >nul
16 for /F "Tokens=1* delims=" %%a IN ('type %blafile%') do call :WriteTmp %1 "%%a"
17 IF "%Dirty%"=="TRUE" call :WriteFinal %~n1-%FileCnt%%~x1
18 echo Datei %1 zerlegt in Dateien %~n1-1%~x1 bis %~n1-%FileCnt%%~x1.
19 goto :eof
20 ---------hier Ende der Welt
21 :WriteTmp
22 Set /a cntln=%cntln%+1
23 IF %cntln% GTR 1 (
24 :: echo FILE: %~n1-%FileCnt%%~x1 LN :%cntln% Text: %~2>>%temp%\tmpbla-%FileCnt%.tmp
25 echo %~2>>%temp%\tmpbla-%FileCnt%.tmp
26 SET Dirty=TRUE
27 If %cntln% EQU %MaxLnsPerFile% call :WriteFinal %~n1-%FileCnt%%~x1 )
28 goto :eof
29 ------- ende WriteTmp-Block...zurück zur FOR.. IN.. DO..Schleife
30 :WriteFinal
31 echo %LastLine% >>"%temp%\tmpbla-%FileCnt%.tmp"
32 Copy /b "%temp%\Headline.Txt"+ "%temp%\tmpbla-%FileCnt%.tmp" "%1" >nul
33 (SET Dirty=FALSE) & (set /a cntln=1) & (set /a FileCnt=%FileCnt%+1)
34 goto :eof
35 ::-----snapp Splitbla.bat Vers. 0.2----
Alles anzeigen
Quelle: http://www.administrator.de/index.php?cont…260dccc49#52233
Geht es etwas einfacher ?
Kenn mich irgendwie nicht aus:(