1 '**************************************************************************
2 '* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 '* Copyright 2008 by Sun Microsystems, Inc.
6 '* OpenOffice.org - a multi-platform office productivity suite
8 '* $RCSfile: t_dirloc.inc,v $
12 '* last change: $Author: jsi $ $Date: 2008-06-13 10:27:10 $
14 '* This file is part of OpenOffice.org.
16 '* OpenOffice.org is free software: you can redistribute it and/or modify
17 '* it under the terms of the GNU Lesser General Public License version 3
18 '* only, as published by the Free Software Foundation.
20 '* OpenOffice.org is distributed in the hope that it will be useful,
21 '* but WITHOUT ANY WARRANTY; without even the implied warranty of
22 '* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 '* GNU Lesser General Public License version 3 for more details
24 '* (a copy is included in the LICENSE file that accompanied this code).
26 '* You should have received a copy of the GNU Lesser General Public License
27 '* version 3 along with OpenOffice.org. If not, see
28 '* <http://www.openoffice.org/license.html>
29 '* for a copy of the LGPLv3 License.
31 '/************************************************************************
33 '* owner : thorsten.bosbach@sun.com
35 '* short description : functions for directories and files; execution happens in the testtool
37 '\************************************************************************
39 function hFileExistsLocal ( Dat as String ) as Boolean
40 '/// Checks if a file exists
41 '/// <u>Input</u>: Filename with complete path
42 '/// <u>Return</u>: TRUE or FALSE if the file exists.
43 if Dir ( Dat ) = "" then
44 hFileExistsLocal = FALSE
46 hFileExistsLocal = TRUE
50 '-------------------------------------------------------------------------------
52 function hDirectoryExistsLocal ( Verz as String ) as Boolean
53 '/// Checks if a directory exists
54 '/// <u>Input</u>: Directory with complete path
55 '/// <u>Return</u>: TRUE or FALSE if the directory exists.
56 ' at the end of the string has to be teh path seperator, else the dir-command doesn't work
57 if right ( Verz, 1 ) <> gPathSigne then Verz = Verz + gPathSigne
58 if Dir ( Verz, 16 ) = "" then
59 hDirectoryExistsLocal = FALSE
61 hDirectoryExistsLocal = TRUE
65 '-------------------------------------------------------------------------------
67 function hKillFileLocal ( Dat as String ) as Boolean
69 '/// <u>Input</u>: File with complete path
70 '/// <u>Return</u>: TRUE or FALSE success on deleting?
71 if Dir ( Dat ) <> "" then
76 if Dir ( Dat ) <> "" then
77 hKillFileLocal = FALSE
86 '-------------------------------------------------------------------------------
88 function DirNameListLocal (ByVal sPfad$ , lsDirName() as String ) as Integer
89 '/// seperate a path in its parts
90 '/// <u>Input</u>: Path to seperate; Empty list, because it get's reset in this function!;
91 '/// <u>Return</u>: Number on entries in the list; list with entries
97 Pos% = InStr(1, sPfad$, "\") ' got a path
98 i% = Val(lsDirName(0) ) + 1
100 lsDirName( i% ) = Left( sPfad$, Pos% ) ' .. put in list
101 sPfad = Mid( sPfad$, Pos% + 1 ) ' ...cut off
103 lsDirName( i% ) = sPfad$
104 DirNameListLocal = i% ' count of
107 '-------------------------------------------------------------------------------
109 function GetFileNameListLocal ( sPath$, sMatch$ ,lsFile() as String ) as integer
110 '/// Get files from a directory that match the pattern and append them to a list (without path)
111 '/// <u>Input</u>: Directory with complete path; Search Pattern, e.g *.*; List
112 '/// <u>Return</u>: count of appended entries; updated list
114 Dim Datname as String
118 if right ( sPath$, 1 ) <> gPathSigne then sPath$ = sPath$ + gPathSigne
119 ' at the end of the string has to be teh path seperator, else the dir-command doesn't work
120 Datname = Dir( sPath$ + sMatch$ , 0)
122 do until Len(Datname) = 0
124 lsFile(Count%) = Datname ' append
129 GetFileNameListLocal = Count% ' all files
132 '-------------------------------------------------------------------------------
134 function GetFileListLocal ( sPath$, sMatch$ ,lsFile() as String ) as integer
135 '/// Get files from a directory that match the pattern and append them to a list (<b>with</b> path)
136 '/// <u>Input</u>: Directory with complete path; Search Pattern, e.g *.*; List
137 '/// <u>Return</u>: count of appended entries; updated list
139 Dim Datname as String
143 if right ( sPath$, 1 ) <> gPathSigne then sPath$ = sPath$ + gPathSigne
144 ' at the end of the string has to be teh path seperator, else the dir-command doesn't work
145 Datname = Dir( sPath$ + sMatch$ , 0)
147 do until Len(Datname) = 0
148 lsFile(0) = Val(lsFile(0)) + 1
149 lsFile( lsFile(0) ) =sPath$ + Datname
153 GetFileListLocal = Count%
156 '-------------------------------------------------------------------------------
158 function GetDirListLocal ( sPath$, sMatch$ ,lsFile() as String ) as integer
159 '/// Get Subdirectories from a directory and append them to a list (<b>with</b> path)
160 '/// <u>Input</u>: Directory with complete path; Search Pattern, e.g *; List
161 '/// <u>Return</u>: count of appended entries; updated list
163 Dim Verzeichnis as String
165 if right ( sPath$, 1 ) <> gPathSigne then sPath$ = sPath$ + gPathSigne
166 ' at the end of the string has to be teh path seperator, else the dir-command doesn't work
167 Verzeichnis = Dir( sPath$ + sMatch$ , 16)
170 do until Len(Verzeichnis) = 0
171 if Verzeichnis <>"." AND Verzeichnis <> ".." then
172 lsFile(0) = Val(lsFile(0)) + 1
173 lsFile( lsFile(0) ) = sPath$ + Verzeichnis + gPathSigne
179 GetDirListLocal = Count%
182 '-------------------------------------------------------------------------------
184 function GetAllDirListLocal ( byVal sPath$, byVal sMatch$ ,lsFile() as String ) as integer
185 '/// Get all directorys recursiv that match the pattern and append them to a list
186 '/// <u>Input</u>: Directory with complete path; Search Pattern, e.g *; Empty list, because it get's reset in this function!;
187 '/// <u>Return</u>: Count of appended entries (1. entry is the whole path); updated list
188 Dim Count% : Dim DirCount%
190 DirCount% = 1 ' dummy
192 lsFile(0) = 1 'new list
193 lsFile(1) = sPath$ 'first path is the calling path
195 do until Count%>Val(lsFile(0)) ' get first generation
196 DirCount% = GetDirListLocal ( lsFile(Count%) , sMatch$, lsFile() ) ' append all subdirectories
200 GetAllDirListLocal = Count% - 1 ' count of listelements
203 '-------------------------------------------------------------------------------
205 function GetAllFileListLocal ( byVal sPath$, byVal sMatch$ ,lsFile() as String ) as integer
206 '/// Get all Files recursiv (including in subdirectories) that match the pattern and append them to a list
207 '/// <u>Input</u>: Directory with complete path; Search Pattern, e.g *.*; Empty list, because it get's reset in this function!;
208 '/// <u>Return</u>: Count of appended entries (1. entry is the whole path); updated list
209 Dim DirCount% : Dim FileCount% : Dim Count%
210 Dim lsDir(1000) as String
212 DirCount% = GetAllDirListLocal ( sPath$, "*", lsDir() ) ' just all directories
217 For Count% = 1 to Val( lsDir(0) )
218 FileCount% = FileCount% + GetFileListLocal ( lsDir( Count% ), sMatch$, lsFile() )
221 GetAllFileListLocal = FileCount% ' count of files
224 '-------------------------------------------------------------------------------
226 function KillFileListLocal ( lsList() as String ) as Boolean
227 '/// Delete all files in the list
228 '/// <u>Input</u>: List with files
229 '/// <u>Return</u>: TRUE or FALSE if files are killed; modified list with not deleted files.
231 Dim FehlerListe ( 1000 ) as String
233 FehlerListe ( 0 ) = 0
234 for i=1 to ListCount ( lsList() )
238 ListAppend ( FehlerListe (), lsList(i) )
242 lsList(0) = 0 ' delete old list
243 KillFileListLocal = TRUE
244 for i=1 to ListCount ( FehlerListe () )
245 KillFileListLocal = FALSE
246 ListAppend ( lsList(), FehlerListe (i) )
250 '-------------------------------------------------------------------------------
252 function KillDirListLocal ( lsList() as String ) as Boolean
253 '/// Delete all directories in the list
254 '/// <u>Input</u>: List with directories
255 '/// <u>Return</u>: TRUE or FALSE if directories are killed; modified list with not deleted directories.
257 Dim FehlerListe ( 1000 ) as String
259 FehlerListe ( 0 ) = 0
260 for i=1 to ListCount ( lsList() )
264 ListAppend ( FehlerListe (), lsList(i) )
268 lsList(0) = 0 ' delete old list
269 KillDirListLocal = TRUE
270 for i=1 to ListCount ( FehlerListe () )
271 KillDirListLocal = FALSE
272 ListAppend ( lsList(), FehlerListe (i) )
276 '-------------------------------------------------------------------------------
278 function GetFileSizesLocal ( lsList() as String ) as long
279 '/// Computes the total Filesize of the files in the list
280 '/// <u>Input</u>: List with files
281 '/// <u>Return</u>: Filesize in bytes
286 for i=1 to ListCount ( lsList() )
288 iSum = iSum + FileLen ( lsList(i) )
293 GetFileSizesLocal = iSum