1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
option explicit
On Error Resume next
dim oWsh, oArgs, oFS, oTS, infile, outfile, f, c, result
', oFS, oEnv, tlroot, script_path, Return, cmd
set oWsh = createobject( "wscript.Shell" )
Set oFS = CreateObject("Scripting.FileSystemObject")
'Set oEnv = oWsh.Environment("PROCESS")
Set oArgs = wscript.arguments
'tlroot = (oFS.GetParentFolderName(oFs.GetParentFolderName( _
' oFS.GetParentFolderName(WScript.ScriptFullName))))
'If Right(tlroot,1) <> "\" Then
' tlroot = tlroot & "\"
'End If
' assume sam2p and bmeps on searchpath
If oArgs.count = 0 Then
messageBox "Nothing to do"
wscript.quit
End If
' name of output file
' may have to flip slashes if the file was on a network drive !!!
infile = replace(oArgs(0), "/", "\")
infile = ofs.getabsolutepathname(infile)
outfile = ofs.buildpath(ofs.getparentfoldername(infile), _
ofs.getbasename(infile) & ".eps")
If ofs.fileexists(outfile) Then
result = MsgBox(outfile & vbcrlf & "exists; overwrite?", _
vbyesno+vbquestion)
If result <> vbyes Then
wscript.quit
Else
oFS.deletefile(outfile)
Err.clear
If ofs.fileexists(outfile) Then
MsgBox "Unable to memove old " & outfile, vbcritical
wscript.quit
End If
End If
End If
' MsgBox "trying sam2p"
owsh.run "sam2p """ & infile & """ EPS: """ & outfile & """", 0
If Err Then
MsgBox "Unspecified failure", vbcritical
wscript.quit
End If
wscript.sleep(1000)
If ofs.fileexists(outfile) Then
MsgBox ofs.getbasename(infile) & "." & ofs.getextensionname(infile) & _
" successfully converted", vbInformation
Else
Err.clear
' clear sam2p temp files
For Each f in ofs.getfolder(ofs.getparentfoldername(infile)).files
If InStr(f.Name, "tmp__sam2p") = 1 Then
f.delete
Err.clear
End If
Next
' MsgBox "trying bmeps"
owsh.run "bmeps -c """ & infile & """ """ & outfile & """", 0
If Err Then
MsgBox "Unspecified failure", vbcritical
wscript.quit
End If
wscript.sleep(1000)
If ofs.fileexists(outfile) Then
result = True
' check the eps file.
' bmeps may have written an error message to it.
Set oTS = ofs.opentextfile (outfile, 1)
If Err Then
result = False
Err.clear
Else
c = oTS.read(2)
If Err Then
result = false
Err.clear
Else
If c <> "%!" Then
result = False
End If
End If
oTS.close
End If
If result then
MsgBox ofs.getbasename(infile) & "." & ofs.getextensionname(infile) & _
" successfully converted with bmeps", vbInformation
Else
'ofs.deletefile(outfile)
MsgBox "Conversion failed", vbCritical
End If
Else
MsgBox "Conversion failed", vbCritical
End If
End If
|