forked from BenSimonds/QlikviewSkeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reduce.vbs
96 lines (75 loc) · 2.98 KB
/
reduce.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
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
' This script loops through the App and QVDLoader Folders and converts any QVWs to reduced ones.
' Currently it isn't recursive. Logs to reduce.vbs.log
'Create filesystem object'
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set Working Directory for relative paths.'
WorkingDir = objFSO.GetParentFolderName(WScript.ScriptFullName)
'Create Logfile'
Set myLog = objFSO.CreateTextFile(WorkingDir & "\reduce.vbs.log")
mylog.WriteLine Now &" Begin logging..."
'Look in App and QVD Loader and reduce files:'
Set QVWPaths = CreateObject("Scripting.Dictionary")
QVWPaths.Add objFSO.GetFolder(WorkingDir & "\App"), ""
QVWPaths.Add objFSO.GetFolder(WorkingDir & "\QVDLoader"), ""
'ADD OTHER FOLDERS TO BE SEARCHED HERE'
'Loop through folders'
mylog.WriteLine Now & " Looping through Folders"
'Open Qlikview'
Set MyApp = CreateObject("QlikTech.QlikView")
For Each QVWPath in QVWPaths.Keys()
mylog.WriteLine Now & " Searching in: " & QVWPath
For Each QVWFile in QVWPath.Files
If UCase(objFSO.GetExtensionName(QVWFile.Name)) = "QVW" AND UCase(Right(QVWFile,7)) <> ".ND.QVW" Then
mylog.WriteLine Now & " Found QVW: " & QVWFile.Name
ReduceData QVWFile
End If
Next
Next
'Quit'
MyApp.Quit
Set MyDoc = Nothing
Set MyApp = Nothing
mylog.WriteLine Now & " ...Vars Dropped."
mylog.WriteLine Now & " Finished!"
'----------------SUBROUTINES----------------'
Sub ReduceData(QVW)
'Source and destination file paths'
BaseName = Left(QVW,Len(QVW)-4)
Target = BaseName & ".nd.qvw"
PRJFolder = BaseName & "-prj"
mylog.WriteLine Now & " Creating No Data File: " & QVW & " >> " & Target
'Open File in Qlik'
Set MyDoc = MyApp.OpenDoc(QVW,"","")
mylog.WriteLine Now & " ...File Opened."
'I hate it when generate logfile isn't turned on, so here I make sure it's done for every file.
set docProp = MyDoc.GetProperties 'Creates a properties object'
If not docProp.GenerateLogfile Then
docProp.GenerateLogfile = true 'Sets GenerateLogfile to true'
MyDoc.SetProperties docProp 'Sets DocProperties to our modified object.'
MyDoc.SaveAs(QVW) 'Saves the doc.'
End If
set docProp = Nothing
mylog.WriteLine Now & " ...Found file with generate logfile turned off. Turned on and re-saved."
'Test prj folder exists:'
If not objFSO.FolderExists(PRJFolder) Then
mylog.WriteLine Now & "PRJ folder not found for " & BaseName
result = MsgBox ("PRJ folder not found for " & BaseName & ". Create?", vbYesNo, "Yes No Example")
Select Case result
Case vbYes
'Create PRJ Folder and populate by saving.'
mylog.WriteLine Now & " ...Creating PRJ folder: " & PRJFolder
Set objFolder = objFSO.CreateFolder(PRJFolder)
mylog.WriteLine Now & " ...Populating PRJ folder: " & PRJFolder
MyDoc.SaveAs(QVW)
Case vbNo
'Do Nothing...'
mylog.WriteLine Now & " ...Doing nothing."
WScript.Sleep(1)
End Select
End IF
'Remove Data and Save'
MyDoc.RemoveAllData
mylog.WriteLine Now & " ...Data Reduced."
MyDoc.SaveAs(Target)
mylog.WriteLine Now & " ...File Saved."
END SUB