Hi i tried make a recursive sub (lotusscript) to listing files and directories on file system, but that sub doesn`t work properly. Can there work recursive subs or funtions? Thank you. Palo
Subject: recursive subs or functions
Sure it works. One example:Sub ValidQuantity
qty = Inputbox("Entrez la quantité désirée", "Quantité")
If Instr(qty, ".") Or Instr(qty, ",") Or Not Isnumeric(qty) Then
Msgbox |Please enter an integer value. (Veuillez saisir une valeur entière).| , 0 + 48, _
"Incorrect value"
Call ValidQuantity
End If
If qty = "" Then Exit Sub
End Sub
HTH
Subject: recursive subs or functions
Hi,
recursive calls are possible, but because the paramter stack reserved by Notes for these kind of calls is very small (32k or 64k, don’t remember exactly) you may soon run into problems .
That’s why i.e. I have written my Quicksort routine as an iterative algorithm.
Joe
Subject: recursive subs or functions
In addition to other problems, I believe that Dir$() doesn’t work recursively, so if you’re trying to use that for this particular purpose, you won’t be able to get it to work.
Subject: RE: recursive subs or functions
Although Dir$() doesn’t work recursively it is possible to write recursive routines to traverse a directory tree by saving the state of Dir$(), which gets popped back off the stack as the function unwinds.
Here’s an example using lists that I put together some time ago to see if we could Compact all the desktop.dsk files in users’ networked home data folders.
Overview:
Given a top level folder as input, the code in this button will recurse down through that folder and its subfolders:
If it finds a file named desktop.dsk or desktop5.dsk it will try to open it as a notes database.
If the database opens, it is compacted
No logging and minimal error checking is used.
v0.1 developing…
Instructions:
Map a drive to the required share
Click the button
Enter the required top-level folder (e.g. F:\Users)
Hope it doesn’t crash due to stack overflow
Sub Click(Source As Button)
Dim startfolder As String
startfolder = Inputbox$("Enter full path to start Folder (i.e. F:\Users)")
If startfolder = "" Then
Exit Sub
End If
Chdrive startfolder ' Uses first letter to set current drive
CompactDesktops(startfolder) ' Call the CompactDesktops function
Messagebox("Updates Complete") ' Show result
End Sub
Function CompactDesktops(toplevel As String) As Long
%REM
A quick and dirty recursive function to find all the names.nsf files in given folder and its sub-folders
call the function with a top-level folder as argument, i.e. f:\Users
Author: John Gundry
Date: 5th November 2003
Version: 0.1
Note1: As with any recursive function you only get 32KB of stack space so if you have hundreds
of subfolders to many levels you may bomb out with an out of stack error so try it on your worst-case
scenario before releasing into the wild!
Note2: Notes R5 Client Only as Dir$() appears a bit ‘flakey’ in R4 and can return unexepected results!
%END REM
Dim dbDsk As NotesDatabase
Dim dirlist List As Integer ' We need to store the files & folders somewhere as the state of Dir$() is not stored on the stack.
If Right$(toplevel, 1) <> "\" Then toplevel = toplevel & "\" 'Stick a backslash on the end if it hasn't already got one
Chdir toplevel ' Change the current directory to toplevel
fileName$ = Dir$(toplevel + "*.*", 55) ' All files and folders including hidden and system
k% = 1 ' Just a counter to index the list
Do While fileName$ <> ""
If Left$(fileName$, 1) <> "." Then ' This lets us ignore "." - current directory and ".." - parent directory
dirlist(toplevel & fileName$) = k%
k% = k% + 1
End If
fileName$ = Dir$() ' Get the next file/folder entry from the current directory (toplevel)
Loop
' Now that we've got all files and folders at the top level we can loop through, checking for desktop files and recursively
' calling CompactDesktops for folders
Forall file In dirlist
fileName$ = Listtag(file) ' This gives us the next file/folder name that we stored earlier
attribute = Getfileattr(fileName$) ' Get the attribute for the file (system, read-only, hidden, folder, etc)
If attribute And 16 Then ' 16 = 'Directory'
CompactDesktops(fileName$) ' If it is a folder we recursively call CompactDesktops function
Else
' we check to see if it is an R4 or 5 Desktop DB. If it is we compact it
If Lcase(Right$(fileName$, 11)) = "desktop.dsk" Or Lcase(Right$(fileName$, 12)) = "desktop5.dsk"Then
Set dbDsk = New NotesDatabase("", fileName$)
If Not(dbDsk.isOpen) Then
Messagebox("Could not Open Desktop: " & fileName$)
Else
Call dbDsk.Compact
End If
End If
End If
End Forall
End Function