program waist; {$apptype console} uses Windows, Sysutils, USListEx, UArgs; var st, InPath: string; OutPath: string; SL: TStringListEx; i, start, count: integer; begin try start := 0; count := 20; InPath := ''; OutPath := ''; for i := 1 to Arguments.Count-1 do begin st := Arguments[i]; if st = '-?' then raise EInOutError.Create(''); case st[1] of '-': try system.Delete(st, 1, 1); start := strtoint(st); except raise EInOutError.CreateFmt('"-%s": Invalid Option.', [st]); end; '+': try system.Delete(st, 1, 1); count := strtoint(st); except raise EInOutError.CreateFmt('"+%s": Invalid Option.', [st]); end; else if InPath = '' then InPath := st else if OutPath = '' then OutPath := st else raise EInOutError.Create('too Args.'); end; end; if (InPath = '') then raise EInOutError.CreateFmt('"%s" Can Not Open.', [InPath]); if (not FileExists(InPath)) then raise EInOutError.CreateFmt('"%s" Not Found.', [InPath]); // 読み込み SL := TStringListEx.Create; SL.LoadFromFile(InPath); // 切り出し if start >= SL.Count then begin SL.Free; exit; end; if start < SL.Count then for i := 0 to start-1 do SL.delete(0); while count < SL.Count do SL.delete(SL.Count-1); // 書き出し SL.SaveToFile(OutPath); SL.Free; except on E: Exception do begin writeln(E.message); writeln('Usage: ', ExtractFileName(ParamStr(0)), ' [-開始行] [+出力行] 入力ファイル [出力ファイル]'); writeln('ex) ', ExtractFileName(ParamStr(0)), ' -80 +40 a01.csv a01%.csv'); end; end; end.