Home All Groups Group Topic Archive Search About

Folder loading problem.

Author
27 May 2005 4:06 PM
Bala
Hi

In my project, Using FindFirstFile,FindNextFile and FindClose APIs, i am
loading the folders in to listbox (for ex c:\temp\). The problem is some of
the clients having this problem,like in that particular folder they have
nearly 50 Sub folders. but the api loads nearly 30 folders, its not loading
the another 20 folders. it seems they all the folders property are same. i
dont know why this happen. not all the clients. very few clients and all the
systems in that particular clients. any idea please.

Thanks
bala

Author
27 May 2005 8:23 PM
Bonj
Check whether it's not finding them at all, or whether it's finding them but
just not adding them to the listbox.
To do this, replace your code that adds them to the listbox with Debug.Print
and see if they get printed.
If it's a problem with the listbox, post the code that adds them to the
listbox.
If it's not finding them at all, then post the code that finds the files.


Show quoteHide quote
"Bala" <B***@discussions.microsoft.com> wrote in message
news:704D05F9-D087-4704-84F4-380CA5B8697B@microsoft.com...
> Hi
>
> In my project, Using FindFirstFile,FindNextFile and FindClose APIs, i am
> loading the folders in to listbox (for ex c:\temp\). The problem is some
> of
> the clients having this problem,like in that particular folder they have
> nearly 50 Sub folders. but the api loads nearly 30 folders, its not
> loading
> the another 20 folders. it seems they all the folders property are same. i
> dont know why this happen. not all the clients. very few clients and all
> the
> systems in that particular clients. any idea please.
>
> Thanks
> bala
Author
27 May 2005 11:49 PM
Bala
Hi Bonj,

Thanks for the reply. Using fso, its loading all the folders into list.

This is the code i am using in my project. i got it from here itself (ms vb
fourm).

Please check the code and let me know if did any mistake.

Thanks
Bala

Code:

'Listbox loading speed functions
Private Sub ListAllFoldersInDirectory(ByVal sPath As String, _
                                           ByRef objListBox As ListBox)

    objListBox.Clear
    Dim wfd As WIN32_FIND_DATA
    Dim hfile As Long
    Dim sFileName As String

    If Right$(sPath, 1) <> "\" Then sPath = sPath & "\"
    hfile = FindFirstFile(sPath & "*.*", wfd)

    If hfile <> -1 Then
        With objListBox
            Do
                sFileName = TrimNull(wfd.cFileName)
                If Chr(Asc(sFileName)) <> "." Then
                    If wfd.dwFileAttributes = vbDirectory Then
                        .AddItem sFileName
                    End If
                End If
            Loop Until FindNextFile(hfile, wfd) = 0
        End With
    End If
    Call FindClose(hfile)

End Sub






Show quoteHide quote
"Bonj" wrote:

> Check whether it's not finding them at all, or whether it's finding them but
> just not adding them to the listbox.
> To do this, replace your code that adds them to the listbox with Debug.Print
> and see if they get printed.
> If it's a problem with the listbox, post the code that adds them to the
> listbox.
> If it's not finding them at all, then post the code that finds the files.
>
>
> "Bala" <B***@discussions.microsoft.com> wrote in message
> news:704D05F9-D087-4704-84F4-380CA5B8697B@microsoft.com...
> > Hi
> >
> > In my project, Using FindFirstFile,FindNextFile and FindClose APIs, i am
> > loading the folders in to listbox (for ex c:\temp\). The problem is some
> > of
> > the clients having this problem,like in that particular folder they have
> > nearly 50 Sub folders. but the api loads nearly 30 folders, its not
> > loading
> > the another 20 folders. it seems they all the folders property are same. i
> > dont know why this happen. not all the clients. very few clients and all
> > the
> > systems in that particular clients. any idea please.
> >
> > Thanks
> > bala
>
>
>
Author
28 May 2005 11:16 AM
J French
See inline :-

On Fri, 27 May 2005 16:49:12 -0700, "=?Utf-8?B?QmFsYQ==?="
<B***@discussions.microsoft.com> wrote:

Show quoteHide quote
>Hi Bonj,
>
>Thanks for the reply. Using fso, its loading all the folders into list.
>
>This is the code i am using in my project. i got it from here itself (ms vb
>fourm).
>
>Please check the code and let me know if did any mistake.
>
>Thanks
>Bala
>
>Code:
>
>'Listbox loading speed functions
>Private Sub ListAllFoldersInDirectory(ByVal sPath As String, _
>                                           ByRef objListBox As ListBox)
>
>    objListBox.Clear
>    Dim wfd As WIN32_FIND_DATA
>    Dim hfile As Long
>    Dim sFileName As String
>
>    If Right$(sPath, 1) <> "\" Then sPath = sPath & "\"
>    hfile = FindFirstFile(sPath & "*.*", wfd)
>
>    If hfile <> -1 Then
>        With objListBox
>            Do
>                sFileName = TrimNull(wfd.cFileName)
>                If Chr(Asc(sFileName)) <> "." Then
                     /_______________/
What on earth is that  /
It should be :
                  If sFileName <> "." Then
                     If sFileName <> ".." Then                 
>                    If wfd.dwFileAttributes = vbDirectory Then

    If (wfd.dwFileAttributes And vbDirectory) = vbDirectory Then

If you test for equality then you'll miss directories with the Archive
bit set (32) and of course the ones with the Hidden and/or System bits
set.  Not to mention all the 'advanced' attributes.


If this was originally posted here then whoever posted it needs a darn
good kicking.   Three serious bugs.

As a matter of principle, I would return the results in an Array, this
sort of code is not that speed critical, and it is useful to have
totally re-useable code.
Author
28 May 2005 4:21 PM
Bala
Hi J French,

Thanks for the message... now i have changed the code like this.. is it Ok?
please guide me.

If Trim(sFileName) <> "." Then
      If Trim(sFileName) <> ".." Then
          If (wfd.dwFileAttributes And vbDirectory) = vbDirectory Then
                       .AddItem sFileName
           End If
      End If
End if

Thanks
bala

Show quoteHide quote
"J French" wrote:

> See inline :-
>
> On Fri, 27 May 2005 16:49:12 -0700, "=?Utf-8?B?QmFsYQ==?="
> <B***@discussions.microsoft.com> wrote:
>
> >Hi Bonj,
> >
> >Thanks for the reply. Using fso, its loading all the folders into list.
> >
> >This is the code i am using in my project. i got it from here itself (ms vb
> >fourm).
> >
> >Please check the code and let me know if did any mistake.
> >
> >Thanks
> >Bala
> >
> >Code:
> >
> >'Listbox loading speed functions
> >Private Sub ListAllFoldersInDirectory(ByVal sPath As String, _
> >                                           ByRef objListBox As ListBox)
> >
> >    objListBox.Clear
> >    Dim wfd As WIN32_FIND_DATA
> >    Dim hfile As Long
> >    Dim sFileName As String
> >
> >    If Right$(sPath, 1) <> "\" Then sPath = sPath & "\"
> >    hfile = FindFirstFile(sPath & "*.*", wfd)
> >
> >    If hfile <> -1 Then
> >        With objListBox
> >            Do
> >                sFileName = TrimNull(wfd.cFileName)
> >                If Chr(Asc(sFileName)) <> "." Then
>                      /_______________/
> What on earth is that  /
> It should be :
>                   If sFileName <> "." Then
>                      If sFileName <> ".." Then                 
> >                    If wfd.dwFileAttributes = vbDirectory Then

>     If (wfd.dwFileAttributes And vbDirectory) = vbDirectory Then
>
> If you test for equality then you'll miss directories with the Archive
> bit set (32) and of course the ones with the Hidden and/or System bits
> set.  Not to mention all the 'advanced' attributes.
>
>
> If this was originally posted here then whoever posted it needs a darn
> good kicking.   Three serious bugs.
>
> As a matter of principle, I would return the results in an Array, this
> sort of code is not that speed critical, and it is useful to have
> totally re-useable code.
>
>
>
Author
29 May 2005 8:41 AM
J French
On Sat, 28 May 2005 09:21:01 -0700, "=?Utf-8?B?QmFsYQ==?="
<B***@discussions.microsoft.com> wrote:

Show quoteHide quote
>Hi J French,
>
>Thanks for the message... now i have changed the code like this.. is it Ok?
>please guide me.
>
>If Trim(sFileName) <> "." Then
>      If Trim(sFileName) <> ".." Then
>          If (wfd.dwFileAttributes And vbDirectory) = vbDirectory Then
>                       .AddItem sFileName
>           End If
>      End If
>End if
>
>Thanks
>bala

It looks Ok - but the two Trim()s are redundant

The TrimNull  will have got the 'proper' file name

Although it should not happen, there might be some devious way of
creating a file/directory that is just a '.' with trailing/leading
spaces.

Incidentally (my fault) the logic should read:

If (wfd.dwFileAttributes And vbDirectory) = vbDirectory Then
   If sFileName <> "." Then
      If sFileName <> ".." Then
         .AddItem sFileName

This is because we are only interested in Directories, so that test
should exclude other suspects /first/
Author
29 May 2005 4:55 PM
Bala
i'll change that code. Thank you so much for your ideas.

-bala

Show quoteHide quote
"J French" wrote:

> On Sat, 28 May 2005 09:21:01 -0700, "=?Utf-8?B?QmFsYQ==?="
> <B***@discussions.microsoft.com> wrote:
>
> >Hi J French,
> >
> >Thanks for the message... now i have changed the code like this.. is it Ok?
> >please guide me.
> >
> >If Trim(sFileName) <> "." Then
> >      If Trim(sFileName) <> ".." Then
> >          If (wfd.dwFileAttributes And vbDirectory) = vbDirectory Then
> >                       .AddItem sFileName
> >           End If
> >      End If
> >End if
> >
> >Thanks
> >bala
>
> It looks Ok - but the two Trim()s are redundant
>
> The TrimNull  will have got the 'proper' file name
>
> Although it should not happen, there might be some devious way of
> creating a file/directory that is just a '.' with trailing/leading
> spaces.
>
> Incidentally (my fault) the logic should read:
>
> If (wfd.dwFileAttributes And vbDirectory) = vbDirectory Then
>    If sFileName <> "." Then
>       If sFileName <> ".." Then
>          .AddItem sFileName
>
> This is because we are only interested in Directories, so that test
> should exclude other suspects /first/
>
>
>
>
Author
29 May 2005 5:08 PM
Bala
Hi

i am having small doubt,

'If (wfd.dwFileAttributes And vbDirectory) = vbDirectory Then'

This code will check the Archive is set 32 ?

thanks
bala

Show quoteHide quote
"J French" wrote:

> On Sat, 28 May 2005 09:21:01 -0700, "=?Utf-8?B?QmFsYQ==?="
> <B***@discussions.microsoft.com> wrote:
>
> >Hi J French,
> >
> >Thanks for the message... now i have changed the code like this.. is it Ok?
> >please guide me.
> >
> >If Trim(sFileName) <> "." Then
> >      If Trim(sFileName) <> ".." Then
> >          If (wfd.dwFileAttributes And vbDirectory) = vbDirectory Then
> >                       .AddItem sFileName
> >           End If
> >      End If
> >End if
> >
> >Thanks
> >bala
>
> It looks Ok - but the two Trim()s are redundant
>
> The TrimNull  will have got the 'proper' file name
>
> Although it should not happen, there might be some devious way of
> creating a file/directory that is just a '.' with trailing/leading
> spaces.
>
> Incidentally (my fault) the logic should read:
>
> If (wfd.dwFileAttributes And vbDirectory) = vbDirectory Then
>    If sFileName <> "." Then
>       If sFileName <> ".." Then
>          .AddItem sFileName
>
> This is because we are only interested in Directories, so that test
> should exclude other suspects /first/
>
>
>
>
Author
30 May 2005 11:28 AM
J French
On Sun, 29 May 2005 10:08:01 -0700, "=?Utf-8?B?QmFsYQ==?="
<B***@discussions.microsoft.com> wrote:

>Hi
>
>i am having small doubt,
>
>'If (wfd.dwFileAttributes And vbDirectory) = vbDirectory Then'
>
>This code will check the Archive is set 32 ?

No the Archive attribute is tested for like this :-

If (wfd.dwFileAttributes And vbArchive ) = vbArchive Then

The basic attributes are the bits of a byte

vbReadOnly    1    Read-only
vbHidden    2    Hidden
vbSystem    4    System
vbDirectory    16    Directory or folder
vbArchive    32    File has changed since last backup

FindFirstFile will return all files, regardless of their attributes,
it is up to you to filter out the 'types' that you don't want
Author
29 May 2005 8:33 PM
Bonj
Don't like your with block, 'Call' syntax, explicit 'ByRef', method call
before declarations, etc. etc., but other than that it looks ok... does it
work though was my question?

Show quoteHide quote
"Bala" <B***@discussions.microsoft.com> wrote in message
news:0DDE9F52-0B28-4EDB-AA5F-595C6ACDDB8B@microsoft.com...
> Hi Bonj,
>
> Thanks for the reply. Using fso, its loading all the folders into list.
>
> This is the code i am using in my project. i got it from here itself (ms
> vb
> fourm).
>
> Please check the code and let me know if did any mistake.
>
> Thanks
> Bala
>
> Code:
>
> 'Listbox loading speed functions
> Private Sub ListAllFoldersInDirectory(ByVal sPath As String, _
>                                           ByRef objListBox As ListBox)
>
>    objListBox.Clear
>    Dim wfd As WIN32_FIND_DATA
>    Dim hfile As Long
>    Dim sFileName As String
>
>    If Right$(sPath, 1) <> "\" Then sPath = sPath & "\"
>    hfile = FindFirstFile(sPath & "*.*", wfd)
>
>    If hfile <> -1 Then
>        With objListBox
>            Do
>                sFileName = TrimNull(wfd.cFileName)
>                If Chr(Asc(sFileName)) <> "." Then
>                    If wfd.dwFileAttributes = vbDirectory Then
>                        .AddItem sFileName
>                    End If
>                End If
>            Loop Until FindNextFile(hfile, wfd) = 0
>        End With
>    End If
>    Call FindClose(hfile)
>
> End Sub
>
>
>
>
>
>
> "Bonj" wrote:
>
>> Check whether it's not finding them at all, or whether it's finding them
>> but
>> just not adding them to the listbox.
>> To do this, replace your code that adds them to the listbox with
>> Debug.Print
>> and see if they get printed.
>> If it's a problem with the listbox, post the code that adds them to the
>> listbox.
>> If it's not finding them at all, then post the code that finds the files.
>>
>>
>> "Bala" <B***@discussions.microsoft.com> wrote in message
>> news:704D05F9-D087-4704-84F4-380CA5B8697B@microsoft.com...
>> > Hi
>> >
>> > In my project, Using FindFirstFile,FindNextFile and FindClose APIs, i
>> > am
>> > loading the folders in to listbox (for ex c:\temp\). The problem is
>> > some
>> > of
>> > the clients having this problem,like in that particular folder they
>> > have
>> > nearly 50 Sub folders. but the api loads nearly 30 folders, its not
>> > loading
>> > the another 20 folders. it seems they all the folders property are
>> > same. i
>> > dont know why this happen. not all the clients. very few clients and
>> > all
>> > the
>> > systems in that particular clients. any idea please.
>> >
>> > Thanks
>> > bala
>>
>>
>>
Author
31 May 2005 11:08 PM
Bala
i tried using debug.print, its not printing. thanks for ur help.

bala

Show quoteHide quote
"Bonj" wrote:

> Don't like your with block, 'Call' syntax, explicit 'ByRef', method call
> before declarations, etc. etc., but other than that it looks ok... does it
> work though was my question?
>
> "Bala" <B***@discussions.microsoft.com> wrote in message
> news:0DDE9F52-0B28-4EDB-AA5F-595C6ACDDB8B@microsoft.com...
> > Hi Bonj,
> >
> > Thanks for the reply. Using fso, its loading all the folders into list.
> >
> > This is the code i am using in my project. i got it from here itself (ms
> > vb
> > fourm).
> >
> > Please check the code and let me know if did any mistake.
> >
> > Thanks
> > Bala
> >
> > Code:
> >
> > 'Listbox loading speed functions
> > Private Sub ListAllFoldersInDirectory(ByVal sPath As String, _
> >                                           ByRef objListBox As ListBox)
> >
> >    objListBox.Clear
> >    Dim wfd As WIN32_FIND_DATA
> >    Dim hfile As Long
> >    Dim sFileName As String
> >
> >    If Right$(sPath, 1) <> "\" Then sPath = sPath & "\"
> >    hfile = FindFirstFile(sPath & "*.*", wfd)
> >
> >    If hfile <> -1 Then
> >        With objListBox
> >            Do
> >                sFileName = TrimNull(wfd.cFileName)
> >                If Chr(Asc(sFileName)) <> "." Then
> >                    If wfd.dwFileAttributes = vbDirectory Then
> >                        .AddItem sFileName
> >                    End If
> >                End If
> >            Loop Until FindNextFile(hfile, wfd) = 0
> >        End With
> >    End If
> >    Call FindClose(hfile)
> >
> > End Sub
> >
> >
> >
> >
> >
> >
> > "Bonj" wrote:
> >
> >> Check whether it's not finding them at all, or whether it's finding them
> >> but
> >> just not adding them to the listbox.
> >> To do this, replace your code that adds them to the listbox with
> >> Debug.Print
> >> and see if they get printed.
> >> If it's a problem with the listbox, post the code that adds them to the
> >> listbox.
> >> If it's not finding them at all, then post the code that finds the files.
> >>
> >>
> >> "Bala" <B***@discussions.microsoft.com> wrote in message
> >> news:704D05F9-D087-4704-84F4-380CA5B8697B@microsoft.com...
> >> > Hi
> >> >
> >> > In my project, Using FindFirstFile,FindNextFile and FindClose APIs, i
> >> > am
> >> > loading the folders in to listbox (for ex c:\temp\). The problem is
> >> > some
> >> > of
> >> > the clients having this problem,like in that particular folder they
> >> > have
> >> > nearly 50 Sub folders. but the api loads nearly 30 folders, its not
> >> > loading
> >> > the another 20 folders. it seems they all the folders property are
> >> > same. i
> >> > dont know why this happen. not all the clients. very few clients and
> >> > all
> >> > the
> >> > systems in that particular clients. any idea please.
> >> >
> >> > Thanks
> >> > bala
> >>
> >>
> >>
>
>
>