Subversion Repositories wimsdev

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
20 reyssat 1
Dim fso,fso_files
2
Dim srcFiles(),tarFiles()
3
Dim FilesCnt
4
 
5
Set fso = CreateObject("Scripting.FileSystemObject")
6
 
7
'Get Files
8
Function GetFiles(ByVal path,ByVal exclude)
9
	Dim folder
10
	fso_files = Array()
11
	If CheckFolder(path) Then
12
		Set folder=fso.GetFolder(path)
13
		Call fso_LoadFiles(folder,exclude)
14
	End If
15
	getFiles = Join(fso_files,";")
16
End Function
17
Function fso_LoadFiles(folder,exclude)
18
	Dim f,cnt
19
	cnt=UBound(fso_files)
20
	If cnt<0 Then cnt=0
21
	ReDim Preserve fso_files(cnt+folder.Files.Count)
22
	For Each f in folder.Files
23
		fso_files(cnt)=f.Path
24
		cnt=cnt+1
25
	Next
26
	'search subfolders
27
	For Each f in folder.SubFolders
28
		If InStr(1,","& exclude &",",","& f.name &",")=0 Then
29
			Call fso_LoadFiles(f,exclude)
30
		End If
31
	Next
32
End Function
33
 
34
Function BuildFileSturcure(ByVal srcPath,ByVal tarPath,ByVal exclude)
35
	'Reset srcFiles(),tarFiles
36
	ReDim srcFiles(0)
37
	ReDim tarFiles(0)
38
	FilesCnt=-1
39
	Call CopyFolderStructure(srcPath,tarPath,exclude)
40
End Function
41
 
42
'CopyFiles
43
Function CopyFiles(ByVal srcPath,ByVal tarPath)
44
	Dim f,srcFolder
45
 
46
	'Append \ to tarPath
47
	If Right(tarPath,1)<>"\" Then tarPath=tarPath+"\"
48
 
49
	Set srcFolder=fso.GetFolder(srcPath)
50
	For Each f in srcFolder.Files
51
		state=jsCheckFileState(f.name,f.path)
52
		If (state=1) Then
53
			'files to be compressed
54
			FilesCnt=FilesCnt+1
55
			ReDim Preserve srcFiles(FilesCnt)
56
			ReDim Preserve tarFiles(FilesCnt)
57
			srcFiles(FilesCnt)=f.path
58
			tarFiles(FilesCnt)=fso.BuildPath(tarPath,f.name)
59
		ElseIf (state=2) Then
60
			'Copy file
61
			Call fso.CopyFile(f.Path,tarPath)
62
		End If
63
	Next
64
End Function
65
 
66
'Copy Folder Structure - calls jsCheckFileState()
67
Function CopyFolderStructure(ByVal srcPath,ByVal tarPath,ByVal exclude)
68
	Dim nsp,ntp,folder,srcFolder
69
 
70
	If CheckFolder(srcPath) And CheckFolder(tarPath) Then
71
		Call CopyFiles(srcPath,tarPath)
72
		Set srcFolder=fso.GetFolder(srcPath)
73
		For Each folder in srcFolder.SubFolders
74
			If InStr(1,","& exclude &",",","& folder.name &",")=0 Then
75
				nsp=fso.BuildPath(srcPath,folder.name)
76
				ntp=fso.BuildPath(tarPath,folder.name)
77
				if Not CheckFolder(ntp) Then fso.CreateFolder(ntp)
78
				Call CopyFolderStructure(nsp,ntp,exclude)
79
			End If
80
		Next
81
	End If
82
End Function
83
 
84
'Get Source file to be compress
85
Function GetSRCFile(ByVal index)
86
	GetSRCFile=srcFiles(index)
87
End Function
88
 
89
'Get Target file to be saved
90
Function GetTARFile(ByVal index)
91
	GetTARFile=tarFiles(index)
92
End Function
93
 
94
'Get Total files to be compressed
95
Function GetTotalFiles()
96
	GetTotalFiles=FilesCnt
97
End Function
98
 
99
' Open file
100
Function OpenFile (Byval file)
101
	Dim forReading, tStream
102
	forReading=1
103
	Set tStream = fso.OpenTextFile(file, forReading)
104
	OpenFile = tStream.ReadAll()
105
End Function
106
 
107
' Save file
108
Function SaveFile(Byval file,Byval content)
109
	Dim forWriting,tStream
110
	forWriting=2
111
	Set tStream=fso.OpenTextFile(file, forWriting,true)
112
	Call tStream.Write(content)
113
	Call tStream.Close()
114
	SaveFile=content
115
End Function
116
 
117
'Check Folder
118
Function CheckFolder(path)
119
	CheckFolder=fso.FolderExists(path)
120
End Function