' BCI單圖自動產生.vbs' 將指定檔案夾中的bmp檔案轉換為bci檔案。
'
' 用法:
' 將包含BMP的檔案夾托拽到該指令檔上執行。
' 產生的bci檔案將放在該檔案夾的bci/子目錄中。
'
' 注意:
' 使用前需要設定一下BREW_AuthTool路徑的環境變數。
' 執行前保證BMP檔案夾中沒有 disc/ 和 bci/ 2個子目錄。
'
' 2006/10/24
' by D.H.
'-------------------------------------------------
' APP NAME
APP_NAME = "BREW-BCI單圖批量產生工具"
'-------------------------------------------------
' BREW BCI AuthoringTool path
BREW_BCI_TOOL = "BREW_AuthTool.com"
'---------------------------
' INIT shell
Set wshshell = CreateObject("WScript.Shell")
'---------------------------
' FileSystem INIT
Dim fs
Set fs = CreateObject( "Scripting.FileSystemObject" )
Const ForReading = 1,ForWriting = 2,ForAppending = 8
'---------------------------
' Access arguments
Set args = WScript.Arguments
If args.count > 0 Then
parentDir = args(0) & "/"
Else
usage = "將bmp檔案夾托拽到該指令檔上。" & vbCr
usage = usage & "或者命令執行:指令碼名 bmp檔案夾名字" & vbCr & vbCr
usage = usage & "確保BMP檔案中沒有子檔案夾 ./disc/;./bci/ " & vbCr
usage = usage & "產生的bci存放的子目錄 bci/ 中。" & vbCr & vbCr
usage = usage & "確保設定了BREW_AuthTool路徑的環境變數。"
MsgBox usage, vbInformation, APP_NAME
WScript.Quit
End If
'---------------------------
' path Setting
If not fs.FolderExists( parentDir ) Then
MsgBox "BMP檔案夾不存在!", vbCritical, APP_NAME
WScript.Quit
End If
Set parentFolder = fs.GetFolder( parentDir )
' bci描述檔案目錄
discDir = parentDir & "disc/"
If not fs.FolderExists( discDir ) Then
fs.createFolder( discDir )
End If
Set discFolder = fs.GetFolder( discDir )
' bci組建目錄
bciDir = parentDir & "bci/"
If Not fs.FolderExists( bciDir ) Then
fs.createFolder( bciDir )
End If
Set bciFolder = fs.GetFolder( bciDir )
'------------------------------------
' CREATE txt discription file
Set fc = parentFolder.Files
For Each srcfile In fc
fname = GetFileName( srcfile.name )
fext = GetFileEx( srcfile.name )
If LCase(fext) = "bmp" Then
filename = discDir & fname & "." & "txt"
Set f = fs.CreateTextFile( filename )
f.writeLine(srcfile.path)
f.close
End If
Next
'---------------------------------------
' CREATE bci file
Set fc = discFolder.Files
fileCnt = 0
For Each txtfile In fc
fname = GetFileName( txtfile.name )
fext = GetFileEx( txtfile.name )
'MsgBox BREW_BCI_TOOL & " -i " & txtfile.path & " -o " & bciDir & fname & ".bci"
wshshell.Run "%COMSPEC% /C " & BREW_BCI_TOOL & " -i " & txtfile.path & " -o " & bciDir & fname & ".bci",,True
fileCnt = fileCnt + 1
Next
'---------------------------------------
' 收尾工作
If fs.FolderExists( discDir ) Then
fs.DeleteFolder( discFolder.path )
End If
'---------------------------------
' REPORT result
report = "Finished." & vbCr
report = report & "產生: " & fileCnt & " 個bci檔案。" & vbCr
report = report & "放在: " + bciDir
MsgBox report, vbInformation, APP_NAME
'****************************
' Function GetFileName
'
Function GetFileName( filename )
GetFileName = Left( filename,InStrRev( filename, "." ) - 1 )
End Function
'****************************
' Function GetFileEx
'
Function GetFileEx( filename )
GetFileEx = Right( filename, Len( filename ) - InStrRev( filename, "." ) )
End Function