1 'encoding UTF-8 Do not remove or change this line!
2 '**************************************************************************
3 '* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 '* Copyright 2008 by Sun Microsystems, Inc.
7 '* OpenOffice.org - a multi-platform office productivity suite
9 '* $RCSfile: t_dir.inc,v $
13 '* last change: $Author: jsi $ $Date: 2008-06-13 10:27:09 $
15 '* This file is part of OpenOffice.org.
17 '* OpenOffice.org is free software: you can redistribute it and/or modify
18 '* it under the terms of the GNU Lesser General Public License version 3
19 '* only, as published by the Free Software Foundation.
21 '* OpenOffice.org is distributed in the hope that it will be useful,
22 '* but WITHOUT ANY WARRANTY; without even the implied warranty of
23 '* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 '* GNU Lesser General Public License version 3 for more details
25 '* (a copy is included in the LICENSE file that accompanied this code).
27 '* You should have received a copy of the GNU Lesser General Public License
28 '* version 3 along with OpenOffice.org. If not, see
29 '* <http://www.openoffice.org/license.html>
30 '* for a copy of the LGPLv3 License.
32 '/************************************************************************
34 '* owner : thorsten.bosbach@sun.com
36 '* short description : functions for directories and files; execution happens in the office
38 '\************************************************************************
40 function hFileExists ( Dat as String ) as Boolean
41 '/// Checks if a file exists
42 '/// <u>Input</u>: Filename with complete path
43 '/// <u>Return</u>: TRUE or FALSE if the file exists.
44 if app.Dir ( Dat ) = "" then
51 '-------------------------------------------------------------------------------
53 function hDirectoryExists ( Verz as String ) as Boolean
54 '/// Checks if a directory exists
55 '/// <u>Input</u>: Directory with complete path
56 '/// <u>Return</u>: TRUE or FALSE if the directory exists.
57 ' at the end of the string has to be teh path seperator, else the dir-command doesn't work
58 if right ( Verz, 1 ) <> gPathSigne then Verz = Verz + gPathsigne
59 if app.Dir ( Verz, 16 ) = "" then
60 hDirectoryExists = FALSE
62 hDirectoryExists = TRUE
66 '-------------------------------------------------------------------------------
68 function hKillFile ( Dat as String ) as Boolean
70 '/// <u>Input</u>: File with complete path
71 '/// <u>Return</u>: TRUE or FALSE success on deleting?
72 if app.Dir ( Dat ) <> "" then
77 if app.Dir ( Dat ) <> "" then
87 '-------------------------------------------------------------------------------
89 function DirNameList (ByVal sPfad$ , lsDirName() as String ) as Integer
90 '/// seperate a path in its parts
91 '/// <u>Input</u>: Path to seperate; Empty list, because it get's reset in this function!;
92 '/// <u>Return</u>: Number on entries in the list; list with entries
96 Pos% = InStr(1, sPfad$, gPathsigne ) ' got a part of teh path
97 i% = Val(lsDirName(0) ) + 1
99 lsDirName( i% ) = Left( sPfad$, Pos% ) ' .. put into list
100 sPfad = Mid( sPfad$, Pos% + 1 ) ' ...cut off
102 lsDirName( i% ) = sPfad$
103 DirNameList = i% ' count of
106 '-------------------------------------------------------------------------------
108 function GetFileNameList ( sPath$, sMatch$ ,lsFile() as String ) as integer
109 '/// Get files from a directory that match the pattern and append them to a list (without path)
110 '/// <u>Input</u>: Directory with complete path; Search Pattern, e.g *.*; List
111 '/// <u>Return</u>: count of appended entries; updated list
112 Dim Count% : Dim Datname as String
115 ' at the end of the string has to be teh path seperator, else the dir-command doesn't work
116 if right ( sPath$, 1 ) <> gPathSigne then sPath$ = sPath$ + gPathSigne
117 Datname = app.Dir( sPath$ + sMatch$ , 0) ' 0: normal files
119 if Right ( Datname, 1 ) = "." then
126 do until Len(Datname) = 0
128 lsFile(Count%) = Datname ' append
133 GetFileNameList = Count% ' All files
136 '-------------------------------------------------------------------------------
138 function GetFileList ( sPath$, sMatch$ ,lsFile() as String ) as integer
139 '/// Get files from a directory that match the pattern and append them to a list (<b>with</b> path)
140 '/// <u>Input</u>: Directory with complete path; Search Pattern, e.g *.*; List
141 '/// <u>Return</u>: count of appended entries; updated list
142 Dim Count% : Dim Datname as String
145 ' at the end of the string has to be teh path seperator, else the dir-command doesn't work
146 if right ( sPath$, 1 ) <> gPathSigne then sPath$ = sPath$ + gPathSigne
147 Datname = app.Dir( sPath$ + sMatch$ , 0)
149 if Right ( Datname, 1 ) = "." then
156 do until Len(Datname) = 0
157 lsFile(0) = Val(lsFile(0)) + 1
158 lsFile( lsFile(0) ) =sPath$ + Datname
161 ' if the number of files in the directory exceeds the arraysize do not
162 ' crash but try to handle the situation gracefully. Of course this
163 ' makes the testresults worthless...
164 if ( Count% = ubound( lsFile() ) ) then
165 warnlog ( "List of files exceeds bounds of array." )
166 printlog( "Processing of this directory will be discontinued." )
167 printlog( "Last processed file was: " & Datname )
168 printlog( "Arraysize is: " & ubound( lsFile() ) )
177 '-------------------------------------------------------------------------------
179 function GetDirList ( sPath$, sMatch$ ,lsFile() as String ) as integer
180 '/// Get Subdirectories from a directory and append them to a list (<b>with</b> path)
181 '/// <u>Input</u>: Directory with complete path; Search Pattern, e.g *; List
182 '/// <u>Return</u>: count of appended entries; updated list
183 Dim iFolderCount as integer
185 ' at the end of the string has to be teh path seperator, else the dir-command doesn't work
186 if right ( sPath$, 1 ) <> gPathSigne then sPath$ = sPath$ + gPathSigne
187 Folder = app.Dir( sPath$ + sMatch$ , 16)
190 do until Len( Folder ) = 0
191 select case ( lcase( Folder ) )
197 lsFile(0) = Val(lsFile(0)) + 1
198 lsFile( lsFile(0) ) = sPath$ + Folder + gPathSigne
199 iFolderCount = iFolderCount + 1
203 GetDirList = iFolderCount
206 '-------------------------------------------------------------------------------
208 function GetAllDirList ( byVal sPath$, byVal sMatch$ ,lsFile() as String ) as integer
209 '/// Get all directorys recursiv that match the pattern and append them to a list
210 '/// <u>Input</u>: Directory with complete path; Search Pattern, e.g *; Empty list, because it get's reset in this function!;
211 '/// <u>Return</u>: Count of appended entries (1. entry is the whole path); updated list
212 Dim Count% : Dim DirCount%
214 DirCount% = 1 ' dummy
216 lsFile(0) = 1 'new list
217 lsFile(1) = sPath$ 'first path is the called path
219 do until Count%>Val(lsFile(0)) ' get count of 1.generation
220 DirCount% = GetDirList( lsFile(Count%) , sMatch$, lsFile() ) ' append all subdirectories
224 GetAllDirList = Count% - 1 ' count of...
227 '-------------------------------------------------------------------------------
229 function GetAllFileList ( byVal sPath$, byVal sMatch$ ,lsFile() as String ) as integer
230 '/// Get all Files recursiv (including in subdirectories) that match the pattern and append them to a list
231 '/// <u>Input</u>: Directory with complete path; Search Pattern, e.g *.*; Empty list, because it get's reset in this function!;
232 '/// <u>Return</u>: Count of appended entries (1. entry is the whole path); updated list
233 Dim DirCount% : Dim FileCount% : Dim Count%
234 Dim lsDir(1000) as String
236 DirCount% = GetAllDirList( sPath$, "*", lsDir() ) ' erstmal _alle_ Verzeichnisse
241 For Count% = 1 to Val( lsDir(0) )
242 FileCount% = FileCount% + GetFileList( lsDir( Count% ), sMatch$, lsFile() )
245 GetAllFileList = FileCount% ' Anzahl aller Dateien
248 '-------------------------------------------------------------------------------
250 function KillFileList ( lsList() as String ) as Boolean
251 '/// Delete all files in the list
252 '/// <u>Input</u>: List with files
253 '/// <u>Return</u>: TRUE or FALSE if files are killed; modified list with not deleted files.
255 Dim FehlerListe ( 1000 ) as String
257 FehlerListe ( 0 ) = 0
258 for i=1 to ListCount ( lsList() )
260 app.kill ( lsList(i) )
262 ListAppend ( FehlerListe (), lsList(i) )
266 lsList(0) = 0 ' delete old list
268 for i=1 to ListCount ( FehlerListe () )
270 ListAppend ( lsList(), FehlerListe (i) )
274 '-------------------------------------------------------------------------------
276 function KillDirList ( lsList() as String ) as Boolean
277 '/// Delete all directories in the list
278 '/// <u>Input</u>: List with directories
279 '/// <u>Return</u>: TRUE or FALSE if directories are killed; modified list with not deleted directories.
281 Dim FehlerListe ( 1000 ) as String
283 FehlerListe ( 0 ) = 0
284 for i=1 to ListCount ( lsList() )
286 app.rmDir ( lsList(i) )
288 ListAppend ( FehlerListe (), lsList(i) )
292 lsList(0) = 0 ' delete old list
294 for i=1 to ListCount ( FehlerListe () )
296 ListAppend ( lsList(), FehlerListe (i) )
300 '-------------------------------------------------------------------------------
302 function PfadExtract ( sFiledat$ ) as string
303 '/// Get the path from a file
304 '/// <u>Input</u>: file with path
305 '/// <u>Return</u>: path without the filename
306 Dim s$ : Dim i% : Dim k%
310 i% = DirNameList( sFileDat$, ls() )
313 ls( 1 ) = ls( 1 ) + ls(k%)
316 PfadExtract = Left( ls(1), Len(ls( 1 ))-1)
319 '-------------------------------------------------------------------------------
321 function hPfadname (Dateipfad$) as string
322 '/// Get the path from a file
323 '/// <u>Input</u>: file with path
324 '/// <u>Return</u>: path without the filename
327 for wh = len(Dateipfad$) to 1 step -1
328 if mid(Dateipfad$,wh,1) = gPathSigne then
329 hpfadname = left(Dateipfad$,wh)
332 hpfadname = Dateipfad$
337 '-------------------------------------------------------------------------------
339 function DateiExtract ( sFileDat$ )
340 '/// Get the filename from a path
341 '/// <u>Input</u>: path with file
342 '/// <u>Return</u>: filename without the path
346 i% = DirNameList( sFileDat$, ls() )
347 DateiExtract = ls(i%)
350 '-------------------------------------------------------------------------------
352 function DateiOhneExt (Datei$) as String
353 '/// Get the filename without the extension
354 '/// <u>Input</u>: filename
355 '/// <u>Return</u>: filename without the extension
360 for wh = 1 to len(dummy)
361 if mid(dummy,wh,1) = "." then
362 dummy = left(dummy,wh - 1)
371 '-------------------------------------------------------------------------------
373 function GetExtention ( Datei as String ) as string
374 '/// Get the extension from a file
375 '/// <u>Input</u>: filename
376 '/// <u>Return</u>: extension of the file
378 for i% = 1 to len ( Datei )
379 if mid(Datei,i%,1) = "." then Datei = right( Datei, len(Datei)-i%)