Quote:
> That's correct i did not set any parameters not sure what to set.
> I just wanted to try your example in a test program before I used it
> in my program.
> Can you help me further please?
I meant parameters in the function call. You had to
call the function to test it, right? So I'm assuming you
copied the function to a .bas, added the required declarations,
and then called the function in a button click? When you
call it you send the folder path and a string variable for
the return data. If there are subfolders you get back
something like "folder1*folder2*folder3" in that string. I think
that Argument Not Optional probably means you skipped
the parameter there. For instance:
Sub Command1_Click()
Dim LRet as long
Dim sFol as string, sRet as string
Dim A1() as string
sFol = "C:\Windows\Desktop"
LRet = EnumSubFolders(sFol, sRet)
if lret > 0 then
A1 = split(sret, "*") ' array of subfolder names.
end if
End Sub
Did you maybe leave out the second variable that returns
the file list?
(Note also, as I mentioned before: I wrote this function for
a limited need. If you deal with folders that have thousands
of subfolders the string concatenation will probably slow
things down at some point. An array would probably be
better storage.)
Quote:
> Ron
> > > Thanks for your post I want to run the function from a command button
but
> > > when I try I get an Compile Error Argument Not Optional can this be
> > resolved?
> > I don't know what you mean by running from a
> > command button. The error sounds like you
> > didn't call the function with both parameters.
> > Do you also have the necessary declarations?
> > Maybe you can post code if you don't figure it out.
> > > Ron
> > > > There's a nice, concise sample here:
> > > > http://vbnet.mvps.org/code/fileapi/foldercontent.htm
> > > > There are 2 functions, to find whether a
> > > > folder contains files and to find whether it
> > > > contains folders. A possible subfolder enum
> > > > deriving from that would be the following:
> > > > Public Function EnumSubFolders(sFolPath As String, sList As String)
As
> > Long
> > > > Dim WFD As WIN32_FIND_DATA
> > > > Dim hFile As Long, fCount As Long, Pt1 As Long
> > > > Dim sName As String
> > > > On Error Resume Next
> > > > hFile = FindFirstFile(sFolPath & "\*.*", WFD)
> > > > If hFile <> INVALID_HANDLE_VALUE Then
> > > > Do
> > > > If ((WFD.dwFileAttributes And vbDirectory) = vbDirectory) Then
> > > > sName = WFD.cFileName
> > > > If Len(sName) > 0 Then
> > > > Pt1 = InStr(sName, Chr$(0))
> > > > If Pt1 > 0 Then sName = Left$(sName, (Pt1 - 1))
> > > > If (sName <> ".") And sName <> ".." Then
> > > > EnumSubFolders = EnumSubFolders + 1
> > > > sList = sList & sName & "*"
> > > > End If
> > > > End If
> > > > End If
> > > > Loop Until FindNextFile(hFile, WFD) = 0
> > > > End If
> > > > Call FindClose(hFile)
> > > > If Len(sList) > 0 Then sList = Left$(sList, (Len(sList) - 1))
> > > > End Function
> > > > The above returns a *-delimited list of folder names
> > > > as string, with the function returning number of folders
> > > > found. The string can then be easily split into an array.
> > > > If you expect to deal with a very large number of folders
> > > > you'd probably want to use an array in the first place.
> > > > Also note: The above requires that the parent folder
> > > > path not have an ending \ when sent in the second
> > > > parameter.
> > > > > Hi
> > > > > Is there a way to check if a folder has a sub folder and if yes
get
> > its
> > > > name,
> > > > > also to loop until no sub folder is found.
> > > > > C:\Weeks Post\Sundays Post\Mondays Post\Tuesdays Post etc.
> > > > > Create Post array
> > > > > Post(0) = Sundays Post
> > > > > Post(1) = Mondays Post
> > > > > Post(2) = Tuesdays Post
> > > > > something like this, can you help?
> > > > > regards
> > > > > Ron
> > > > .
> > .