program now; {$apptype console} uses Windows, SysUtils; function shell(const commandline: pchar): integer; cdecl; external 'CRTDLL.DLL' name 'system'; function EvalDateTimeMacro(st: string): string; var i, istart, iend: integer; begin result := ''; istart := 1; iend := 0; i := 1; while i<=length(st) do begin case st[i] of '{': begin result := result + copy(st, iend+1, i-iend-1); istart := i; end; '}': begin result := result + FormatDateTime( copy(st, istart+1, i-istart-1), SysUtils.now); iend := i; end; '\': begin result := result + copy(st, iend+1, i-iend-1); istart := i; i := i + 1; result := result + copy(st, i, 1); iend := i; end; end; i := i + 1; end; if istart < iend then result := result + copy(st, iend+1, length(st)); if result = '' then result := st; end; const CRLF = ^M^J; stUsage = 'now Version 1.00 Copyright (c) 1992,99 by arima.yasuhiro@nifty.com' + CRLF + '使用方法' + CRLF + ' now Command' + CRLF + ' Command:' + CRLF + ' コマンド中のマクロを展開してから実行する.' + CRLF + ' マクロは、"{" と "}" で囲む.' + CRLF + ' マクロとして解釈しないためには "\" を前置する.' + CRLF + '実行例' + CRLF + ' now echo \{ It is {c} \}' + CRLF + ' now mkdir ..\\{yyyymmdd}' + CRLF + ' now copy *.* ..\\{yyyymmdd}' + CRLF + '内容 マクロ文字列' + CRLF + ' 元号 g, gg, ggg' + CRLF + ' 元号年 e, ee' + CRLF + ' 年 yy, yyyy' + CRLF + ' 月 m, mm, mmm, mmmm' + CRLF + ' 日付 d, dd, ddd, dddd, ddddd, dddddd' + CRLF + ' 曜日 aaa, aaaa' + CRLF + ' 時 h, hh' + CRLF + ' 分 n, nn' + CRLF + ' 秒 s, ss' + CRLF + ' 時刻 t, tt' + CRLF + ' 日付 c'; procedure Usage(cond: integer); begin write(stUsage); halt(cond); end; var NewCmdLine: string; i: integer; begin if ParamCount = 0 then Usage(1); NewCmdLine := CmdLine; if NewCmdLine[1] = '"' then begin delete(NewCmdLine, 1, 1); i := pos('"', NewCmdLine); delete(NewCmdLine, 1, i+1); end else begin i := pos(' ', NewCmdLine); delete(NewCmdLine, 1, i); end; trim(NewCmdLine); if NewCmdLine = '' then Usage(2); NewCmdLine := EvalDateTimeMacro(NewCmdLine); shell(pchar(NewCmdLine)); end.