ラブびあ

ビール。ときどきラブ

VB6コンパイルスクリプト

まとめてコンパイルするときに使うスクリプト。他の言語でもコマンドラインをアレンジして使える。それとディレクトリサーチのテンプレ。

'-----------------------------------------------------------------------
' VB6コンパイルスクリプト
'-----------------------------------------------------------------------
' カレント配下のvbp(VBプロジェクトファイル)を検索して、
' binフォルダへexeを出力します
' ├vb6.vbs
' ├projectA   ┐
' ├projectB   │入力
' ・・・          │
' ├projectZ   ┘
' └bin        ┐
'   ├A.exe    │出力
'   ├B.exe    │
'   ・・・        │
'   └Z.exe    ┘
'-----------------------------------------------------------------------
Option Explicit

const vb6exe = "C:\Program Files\Microsoft Visual Studio\VB98\vb6.exe"
const vbHide = 0
dim vbp
dim outdir
dim wsh
dim fso
dim root
dim msg

init
dive root
fini

msgbox msg & "コンパイルが完了しました。"
WScript.Quit

sub init()
	set wsh = CreateObject("Wscript.Shell")  
	set fso = CreateObject("Scripting.FileSystemObject")
	set root = fso.GetFolder(fso.GetParentFolderName(Wscript.ScriptFullName))
	outdir = fso.BuildPath(root.Path, "bin")
	if not fso.FolderExists(outdir) then
		fso.CreateFolder(outdir)
	end if
end sub

sub fini()
	set wsh = Nothing
	set fso = Nothing
	set root = Nothing
end sub

sub dive(p)
	dim f
	for each f in p.Files
		compile f
	next

	dim c
	for each c in p.SubFolders
		dive c
	next
end sub

sub compile(f)
	'vbpファイル以外はスキップ
	if strcomp("vbp", fso.GetExtensionName(f.Name), vbTextCompare) <> 0 then
		exit sub
	end if

	msg = msg & f.Name & vbCrLf
	vbp = f.Path
	wsh.Run cmd("""%vb6exe%"" /make ""%vbp%"" -outdir ""%outdir%"""), vbHide, True
end sub

function cmd(s) 'パラメータを展開する
	cmd = s
	with CreateObject("VBScript.RegExp")
		.Pattern = "%([^%]+)%"
		.Global = True
		do while .Test(cmd)
			dim par
			for each par in .Execute(cmd)
				Execute "cmd = Replace(cmd, par, " + par.subMatches(0) + ")"
			next
		loop
	end with
end function