<job>
<object id = objCmd progID = "ADODB.Command"/>
<reference object = "ADODB.Command"/>
<object id = objFSO progID = "Scripting.FileSystemObject"/>
<reference object = "Scripting.FileSystemObject"/>
<!-- Correct the schema below to reflect your files'
actual fields and their arrangements in the
original and new-format files.
-->
<resource id="resSchema">
[$OrigFile$]
ColNameHeader=False
MaxScanRows=1
Format=FixedLength
Col1=Item Text Width 5
Col2=Animal Text Width 10
Col3=Needed Text Width 1
[$NewFile$]
ColNameHeader=False
MaxScanRows=1
Format=FixedLength
Col1=Needed Text Width 1
Col2=Animal Text Width 10
Col3=Item Text Width 5
</resource>
<resource id = resConnString>
Provider=Microsoft.Jet.OLEDB.4.0;
Extended Properties="Text";
Data Source="$DataPath$"
</resource>
<resource id = "resSQL">
SELECT * INTO [$NewFile$]
FROM [$OrigFile$]
</resource>
<script language = "VBScript">
Option Explicit
Const kstrMyName = "Rearrange fixed fields"
Dim tsSchema
Dim strSFN
Dim strDataPath
Dim strOrigFile
Dim strNewFile
Dim lngRecords
Function Resource(ByVal ResName)
'Fetch resource string, perform text substitutions,
'return the result.
Resource = _
Replace(Replace(Replace(getResource(ResName), _
"$NewFile$", strNewFile), _
"$OrigFile$", strOrigFile), _
"$DataPath$", strDataPath)
End Function
'Use script's path as our data path in this example.
strSFN = WScript.ScriptFullName
strDataPath = Left(strSFN, InStrRev(strSFN, "\") - 1)
'Set original and new filenames. Do NOT try to use
'filenames like out, output, in, input, in.txt, etc.
'these are illegal here.
strOrigFile = "orig.txt"
strNewFile = "new.txt"
'Create schema file, overwriting any already present.
Set tsSchema = _
objFSO.CreateTextFile(strDataPath & "\schema.ini", _
True)
tsSchema.Write Resource("resSchema")
tsSchema.Close
Set tsSchema = Nothing
'Open connection and perform the SQL operation.
objCmd.ActiveConnection = Resource("resConnString")
objCmd.CommandText = Resource("resSQL")
objCmd.Execute lngRecords, , adCmdText Or adExecuteNoRecords
'Delete the schema file, we're done with it.
objFSO.DeleteFile strDataPath & "\schema.ini", True
'Signal completion.
MsgBox "Done! File contains " & CStr(lngRecords) _
& " records.", 0, kstrMyName
</script>
</job>