Everlas
asked on
Find folder with two unknown parameters
Hi
Need to find a folder in a path like
\\servername\knownfolderna me\unknown foldername \partially knownfolde rname
I need the ouput to be the unknownfoldername. I know that there is exactly one possible value.
For the partiallyknownfoldername there may be multiple values.
Everlas
Need to find a folder in a path like
\\servername\knownfolderna
I need the ouput to be the unknownfoldername. I know that there is exactly one possible value.
For the partiallyknownfoldername there may be multiple values.
Everlas
Did that get the job done, or did you need something different?
~bp
~bp
ASKER
Hi
It looked quite simple, but I get the error "invalid outside procedure" when I get to "partialfoldername", so I can't get it to run.
Everlas
It looked quite simple, but I get the error "invalid outside procedure" when I get to "partialfoldername", so I can't get it to run.
Everlas
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry, should have seen the problem myself. Works perfectly. Thanks.
However, I wonder why I get hourglass after the msgbox. Should the End if not kill the sub instantly? Is it just the closing down which is slow?
Do you know if the same result could have been accomplished with the Dir command?
Everlas
However, I wonder why I get hourglass after the msgbox. Should the End if not kill the sub instantly? Is it just the closing down which is slow?
Do you know if the same result could have been accomplished with the Dir command?
Everlas
While the msgbox is open you mean? That would be logical as the msgbox blocks the program. Or after you press OK? It will keep checking the rest of the folders but it shouldn't take very long unless you've got 1000s of folders.
"Dir" could be possible but I've done very little with that, I think it has a lot fewer options than you get with the FileSystemObject.
"Dir" could be possible but I've done very little with that, I think it has a lot fewer options than you get with the FileSystemObject.
So, this may or may not still interest you, but I felt challenged to find a solution with VBA's Dir command and here it is, maybe not the most elegant but works for me ;-)
Option Explicit
Const strPath = "\\servername\knownfoldername" ' fill in the base path here
Sub runcode2()
Dim dn As String
Dim arrdn() As String
Dim cntdn As Integer
cntdn = -1
dn = Dir(strPath & "\", vbDirectory) ' note: returns all entries, files as well
While dn <> ""
If dn <> "." And dn <> ".." And (GetAttr(strPath & "\" & dn) And vbDirectory) = vbDirectory Then
cntdn = cntdn + 1
ReDim Preserve arrdn(cntdn)
arrdn(cntdn) = dn
End If
dn = Dir
Wend
Dim arrSearch
arrSearch = Array("partiallyknownfoldername", "xyz") ' find one of these values in sub-subfolder names
Dim i As Integer
For i = 0 To cntdn
Dim pn
For Each pn In arrSearch
'Debug.Print "checking: " & arrdn(i) & " for '*" & pn & "*'"
dn = Dir(strPath & "\" & arrdn(i) & "\*" & pn & "*", vbDirectory)
While dn <> ""
If (GetAttr(strPath & "\" & arrdn(i) & "\" & dn) And vbDirectory) = vbDirectory Then
Debug.Print "found: " & dn & " under " & arrdn(i)
i = cntdn ' exit outer For as well
Exit For
End If
dn = Dir
Wend
Next
Next
End Sub
ASKER
Yes, still interested. And I'm going to check it out. In the end the task is to create a script that doesn't break the server or the computer and is more or less independent of any speciel configuration on the actual computer. And to an extent backward compatible.
I guess that if the the filesystem is very large an complex, one might create a small database as an alternative to searching the filesystem. Someday classic filesystems as such stop to exist and then we do it in another way :-)
Regards
Everlas
I guess that if the the filesystem is very large an complex, one might create a small database as an alternative to searching the filesystem. Someday classic filesystems as such stop to exist and then we do it in another way :-)
Regards
Everlas
Open in new window