...and another... Mark Taylor 30.Nov.18 11:00 PM a Web browser Notes Client All ReleasesAll Platforms
You don't mention - are you looking for a specific file in a specific location? Or do you have to search the entire drive for a specific file?
--------------------------------
A solution to get directories and files in LotusScript
Posted by Sultan Yakalelo on 31.Jan.01 at 02:11 PM using a Web browser
Category: Domino Designer -- LotusScriptRelease: All ReleasesPlatform: Windows NT
Below is one solution to get all directories and files from a specified location, something many developers seem to struggle around (see technote #172128, in which the workaround Lotus gave was not satisfying either because I was still getting the "Illegal function call" error).
More specifically, the function gets files and directories from one location and copies them into another location by using arrays and recursion. Hence, be careful, whereever there is recursion, there might be possible memory problems if too many recursive calls are made.
It saves all the content of a directory into an array and then loops through that array.
If it finds a directory when looping through the array, the function recursively calls itself (with the new parameters including the directory found);
Else copies the files into the appropriate directory.
Any comments/suggestions/questions/remarks welcome!
Sub gCopyMultipleFiles(Byval vstrFromPath As String, Byval vstrToPath As String)
Dim astrFileList() As String
Dim strDirOrFile As String
Dim intCount As Integer, i As Integer
intCount=0
strDirOrFile$ = Dir$(vstrFromPath & "\", ATTR_DIRECTORY)
While (strDirOrFile$ <> "")
If Not(strDirOrFile$ = "." Or strDirOrFile$ = "..") Then ' Do not save . and .. directories (current and parent directories)
Redim Preserve astrFileList(intCount)
astrFileList(intCount) = strDirOrFile$
intCount = intCount + 1
End If
strDirOrFile$=Dir$()
Wend
If Not(gintDirectoryExists(vstrToPath & "\")) Then ' If it is a new directory, create it
Mkdir vstrToPath
End If
For i = 0 To intCount-1
strDirOrFile$ = astrFileList(i)
If gintDirectoryExists(vstrFromPath & "\" & strDirOrFile$ & "\") Then
' We have a sub-directory, go into that sub-directory by calling gCopyMultipleFiles with parameters including the new directory
gCopyMultipleFiles vstrFromPath & "\" & strDirOrFile$, vstrToPath & "\" & strDirOrFile$
Else
' We have a file, copy it into current directory
gCopyFile vstrFromPath & "\" & strDirOrFile$, vstrToPath & "\" & strDirOrFile$, True
End If
Next
End Sub
Sub gCopyFile(Byval vstrFromFilePath As String, Byval vstrToFilePath As String)
' Copies a file from one location to the other. For additional security, you can check if the source file exists
' at the source and destination, if you can overwrite it etc.
On Error Resume Next
Filecopy vstrFromFilePath, vstrToFilePath ' Copy the source to the destination, the calling routine should handle error
If Err Then
Error Err, strErrorPrefix & Cstr(Error)
Exit Sub
End If
On Error Goto 0
End Sub
Public Function gintDirectoryExists(Byval vstrDirectoryPath) As Integer
' Checks whether a directory exists, returns true or false
Dim strDirectoryFound As String
gintDirectoryExists=False
On Error Resume Next
strDirectoryFound = Dir$(vstrDirectoryPath, ATTR_DIRECTORY)
If Err Then
Err=0
Exit Function
End If
On Error Goto 0
If strDirectoryFound <> "" Then
gintDirectoryExists=True
End If
End Function