Sub Folders 
Author Message
 Sub Folders

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



Sat, 12 May 2012 17:52:06 GMT  
 Sub Folders

Quote:
> 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?

You have to enumerate all sub items, and check if they are a directory
or not.

Either use Dir() and GetAttr() or FindFirst/NextFile()

--

i-Catcher Development Team

iCode Systems



Sat, 12 May 2012 20:42:12 GMT  
 Sub Folders
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.

Quote:
> 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



Sat, 12 May 2012 22:08:02 GMT  
 Sub Folders
Hi mayayana
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?

Ron

Quote:

> 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

> .



Sun, 13 May 2012 01:29:01 GMT  
 Sub Folders

Quote:
> 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.

Quote:
> 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

> > .



Sun, 13 May 2012 01:46:03 GMT  
 Sub Folders
Hi mayayana
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?

Ron

Quote:

> > 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

> > > .

> .



Sun, 13 May 2012 19:00:04 GMT  
 Sub Folders

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

> > > > .

> > .



Sun, 13 May 2012 22:47:03 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Build XML of folders, sub folders and files from specified folder

2. Creating (sub-sub-)folders

3. Enumerate a Folder and it's Sub Folders

4. To get the names of folders and sub folders

5. Find Sub Folder Name within a Folder

6. Deleting certian Files in Folders and there sub folders

7. Copy the files and sub folders to another folder

8. Select contact sub-folder In Outlook

9. Reading Calendar Sub-Folders

10. Getting Sub Folder Access

11. Validate contact in sub folder from Access

12. Reading Calendar Sub-Folders

 

 
Powered by phpBB® Forum Software