File: fsobject.vbs

package info (click to toggle)
wims 2%3A4.29a%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 185,704 kB
  • sloc: xml: 366,687; javascript: 120,570; ansic: 62,341; java: 62,170; sh: 7,744; perl: 3,937; yacc: 3,217; cpp: 1,915; lex: 1,805; makefile: 1,084; lisp: 914; pascal: 601; python: 520; php: 318; asm: 7
file content (120 lines) | stat: -rw-r--r-- 3,077 bytes parent folder | download | duplicates (9)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
Dim fso,fso_files
Dim srcFiles(),tarFiles()
Dim FilesCnt

Set fso = CreateObject("Scripting.FileSystemObject")

'Get Files
Function GetFiles(ByVal path,ByVal exclude)
	Dim folder
	fso_files = Array()
	If CheckFolder(path) Then
		Set folder=fso.GetFolder(path)
		Call fso_LoadFiles(folder,exclude)
	End If
	getFiles = Join(fso_files,";")
End Function
Function fso_LoadFiles(folder,exclude)
	Dim f,cnt
	cnt=UBound(fso_files)
	If cnt<0 Then cnt=0
	ReDim Preserve fso_files(cnt+folder.Files.Count)
	For Each f in folder.Files
		fso_files(cnt)=f.Path
		cnt=cnt+1
	Next
	'search subfolders
	For Each f in folder.SubFolders
		If InStr(1,","& exclude &",",","& f.name &",")=0 Then
			Call fso_LoadFiles(f,exclude)
		End If
	Next
End Function

Function BuildFileSturcure(ByVal srcPath,ByVal tarPath,ByVal exclude)
	'Reset srcFiles(),tarFiles
	ReDim srcFiles(0)
	ReDim tarFiles(0)
	FilesCnt=-1
	Call CopyFolderStructure(srcPath,tarPath,exclude)
End Function

'CopyFiles
Function CopyFiles(ByVal srcPath,ByVal tarPath)
	Dim f,srcFolder
	
	'Append \ to tarPath
	If Right(tarPath,1)<>"\" Then tarPath=tarPath+"\"
	
	Set srcFolder=fso.GetFolder(srcPath)
	For Each f in srcFolder.Files
		state=jsCheckFileState(f.name,f.path)
		If (state=1) Then
			'files to be compressed
			FilesCnt=FilesCnt+1
			ReDim Preserve srcFiles(FilesCnt)
			ReDim Preserve tarFiles(FilesCnt)
			srcFiles(FilesCnt)=f.path
			tarFiles(FilesCnt)=fso.BuildPath(tarPath,f.name)
		ElseIf (state=2) Then
			'Copy file
			Call fso.CopyFile(f.Path,tarPath)
		End If
	Next
End Function

'Copy Folder Structure - calls jsCheckFileState()
Function CopyFolderStructure(ByVal srcPath,ByVal tarPath,ByVal exclude)
	Dim nsp,ntp,folder,srcFolder
		
	If CheckFolder(srcPath) And CheckFolder(tarPath) Then
		Call CopyFiles(srcPath,tarPath)
		Set srcFolder=fso.GetFolder(srcPath)
		For Each folder in srcFolder.SubFolders
			If InStr(1,","& exclude &",",","& folder.name &",")=0 Then
				nsp=fso.BuildPath(srcPath,folder.name)
				ntp=fso.BuildPath(tarPath,folder.name)
				if Not CheckFolder(ntp) Then fso.CreateFolder(ntp)
				Call CopyFolderStructure(nsp,ntp,exclude)
			End If
		Next
	End If
End Function

'Get Source file to be compress
Function GetSRCFile(ByVal index)
	GetSRCFile=srcFiles(index)
End Function

'Get Target file to be saved
Function GetTARFile(ByVal index)
	GetTARFile=tarFiles(index)
End Function

'Get Total files to be compressed
Function GetTotalFiles()
	GetTotalFiles=FilesCnt
End Function

' Open file
Function OpenFile (Byval file)
	Dim forReading, tStream
	forReading=1
	Set tStream = fso.OpenTextFile(file, forReading)
	OpenFile = tStream.ReadAll()
End Function

' Save file
Function SaveFile(Byval file,Byval content)
	Dim forWriting,tStream
	forWriting=2
	Set tStream=fso.OpenTextFile(file, forWriting,true)
	Call tStream.Write(content)
	Call tStream.Close()
	SaveFile=content
End Function

'Check Folder
Function CheckFolder(path)
	CheckFolder=fso.FolderExists(path)
End Function