Created
September 2, 2011 13:47
-
-
Save froop/1188622 to your computer and use it in GitHub Desktop.
[VBScript] CSVファイルからMDBファイルを作成するサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
dim MdbName | |
MdbName = WScript.Arguments(0) | |
Const CSVDir = "." | |
Const MDBDir = "." | |
Const MDBLang = ";LANGID=0x0411;CP=932;COUNTRY=0" | |
'空のMDBファイル作成 | |
Dim WS, DB | |
Set WS = CreateObject("DAO.DBEngine.36").WorkSpaces(0) | |
Set DB = WS.createDatabase(MDBDir + "\" + MdbName + ".mdb", MDBLang) | |
'カレントディレクトリの".csv"ファイルを読み込み | |
Dim RE, FS, ItemFile | |
Set RE = CreateObject("VBScript.RegExp") | |
RE.Pattern =".*\.csv" | |
Set FS = CreateObject("Scripting.FileSystemObject") | |
For Each ItemFile in FS.GetFolder(CSVDir).Files | |
If RE.Test(ItemFile.name) then | |
Dim FileName, TableName | |
FileName = FS.GetBaseName(ItemFile.name) | |
TableName = Replace(FileName, " ", "_") | |
DB.Execute "select * into " + TableName + " from " _ | |
+ "[TEXT;DATABASE=" + CSVDir + "].[" + FileName + "#csv]" | |
End If | |
Next |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
元CSVの数値項目は「"」で囲む。32ビット符号付き整数をオーバーフローするとNULLになるので。