Lotusscript search windows directory for subdirect

2019-07-20 02:39发布

问题:

I'm trying to write a LS agent to scan a directory in windows eg:'C:\' for any files and sub-directories. For each sub-directory, it will go inside and search for more files and sub-directories and continues until there's no more to look for. I'm used to write recursive code to replace or remove characters in a long string but for this one I'm totally lost. Below is my code (it's a mix of code from the domino help file and one I found in IBM site):

Sub Initialize
    Dim pathname As String, filename As String
    pathname = "C:\*.*"
    filename = Dir(pathname, 16)
    Print "Begin scan"
    Do While filename<>""
        If IsDir(pathname+filename)=True Then
            Print pathname+filename+" is a directory"
            'look for more directories and files in here
        Else
            Print filename+" is a file"
        End If
        filename=Dir()
    Loop
    Print "Finish scan"
End Sub

Function IsDir(Path As String) As Integer 
    Dim Void&
    Dim Result As Boolean
    On Error GoTo ErrorHandler
    Void=FileLen(Path)
    Result=False
    GoTo Over
ErrorHandler:
    Result=True
    Resume Over
Over:
    IsDir=Result
End Function

What do I need to change to make the code recursive at the commented part? ('look for more directories and files in here). I'm not just trying to find a specific file or directory. I want all that's available withing one. If I'm able to do that, then I can retrieve them and save into a NotesDocument.

回答1:

I've used this solution a couple of times and it works a treat:



回答2:

First of all, you don't want to call Initialize recursively. You need a function that you're passing a pathname into.

Secondly, because of the stateful way that the DIR function works, I think you have to do this with two loops. In the first loop, you process your regular files and you put the folder names ino a list. Then in the second loop, you go through the list of folders and call the recursive function passing in the path to each one.