-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLib_VBScriptAdditions.vbs
More file actions
83 lines (65 loc) · 3.46 KB
/
Copy pathLib_VBScriptAdditions.vbs
File metadata and controls
83 lines (65 loc) · 3.46 KB
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
' Copyright (C) 2015 Justin MASSIOT
' Author: Justin MASSIOT ( m [dot] just1 !at! free [dot] fr )
' ============================================================================ '
' '
' This program is free software: you can redistribute it and/or modify '
' it under the terms of the GNU Lesser General Public License as '
' published by the Free Software Foundation, either version 3 of the '
' License, or (at your option) any later version. '
' '
' This program is distributed in the hope that it will be useful, '
' but WITHOUT ANY WARRANTY; without even the implied warranty of '
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the '
' GNU Lesser General Public License for more details. '
' '
' You should have received a copy of the GNU Lesser General Public '
' License along with this program. '
' If not, see <http://www.gnu.org/licenses/>. '
' '
' ============================================================================ '
' Altium®, Altium Designer®, DXP™ and their respective logos are trademarks or registered trademarks of Altium Limited or its subsidiaries. See the full Copyright at http://www.altium.com/copyrights-and-trademarks and the EULA at http://www.altium.com/eula .
' All other registered or unregistered trademarks referenced herein are the property of their respective owners.
' ------------------------------------------------------------------------------
' VBScript workarounds and feature enhancements
' To use them, you need to include this file in your scripting project, or simply copy/paste the functions in the content of your file.
' determine if a file exists
Function DoesFileExist (path)
If TypeName(path) <> "String" Or path = "" Then
DoesFileExist = False
Exit Function
End If
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(path)) Then
DoesFileExist = True
Else
DoesFileExist = False
End If
End Function
' inline 'if' statement, replacement of a ternary operator
Function iIf (expression, valIfTrue, valIfFalse)
If (expression) Then
iIf = valIfTrue
Else
iIf = valIfFalse
End If
End Function
' this is a workaround to replace the Try - Catch statement that does not exist in VBScript
Function TryCmd (StrCmd)
If TypeName(StrCmd) <> "String" Or StrCmd = "" Then
TryCmd = False
Exit Function
End If
On Error Resume Next ' if an error occurs, discard it and go to the next instruction (= enable errors handling)
Err.Clear ' clear previous errors
ExecuteGlobal StrCmd ' execute (evaluate) the user command, which is a string
If Err.Number <> 0 Then ' there is an error
TryCmd = False
'ShowWarning "Error: " & Err.Number & vbCrLf &_
' "Error (Hex): " & Hex(Err.Number) & vbCrLf &_
' "Source: " & Err.Source & vbCrLf &_
' "Description: " & Err.Description
Else
TryCmd = True
End If
On Error Goto 0 ' disables the 'On Error Resume Next' statement (= disable errors handling)
End Function