-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.vbs
62 lines (57 loc) · 1.33 KB
/
functions.vbs
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
Function FileExists(filename)
If fso.FileExists(filename) then FileExists=true Else FileExists=false
End Function
Function SaveToFile(filename, data)
' Save data to filename
Dim f
Set f = fso.CreateTextFile(filename)
f.write data
f.close
Set f = nothing
End Function
Function AppendToFile(filename, data)
' Append data to filename, will create file If it doesn't exist
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim f
set f = fso.OpenTextFile(filename, 8, true)
f.write data
f.close
Set f = nothing
End Function
Function LoadFromFile(filename, ByRef data)
' Load data from filename
Dim f
Set f = fso.OpenTextFile(filename)
data = f.ReadAll
f.close
Set f = nothing
End Function
Function LoadFromFileTop(filename, ByRef data, top)
' Load top n lines of data from filename
Dim f
Set f = fso.OpenTextFile(filename)
Dim i
i = 0
Do While Not f.AtEndOfStream And i < top
i = i + 1
data = data & f.ReadLine & vbNewLine
Loop
f.close
Set f = nothing
End Function
Function DeleteFile(filename)
' Load data from filename
Dim f
On Error Resume Next
Set f = fso.GetFile(filename)
If Err=0 then
f.Delete()
Set f = Nothing
DeleteFile = true
Else
DeleteFile = false
End If
On Error Goto 0
Set f = nothing
End Function