FileListBox

Hi,

I need to access all files of a certain type within a folder. I am currently using FileListBox, setting the pattern to "*.yld" and then using .listcount to see how many files there are.

My problem is I came accross a folder with just over 40,000 files in it, and as FileListBox appears to be unsigned 16 bit, the result I got from .listcount was negative.

Is there another way of seeing all these files, or is there a 32 bit equivelant of FileListBox out there?

Regards

Comments

  • Use the Dir() function.

    The first call to Dir you have to specify the search:
    [code]
    Dim sTemp As String
    Dim lCount As Long

    lCount = 0
    sTemp = Dir("C:Directory*.ext")

    [/code]
    You might have to set flags using the second paramater to include System files/Hidden Files.

    Then the next step would be to start counting the rest of the files:
    [code]
    Do While sTemp <> ""
    lCount = lCount + 1
    sTemp = Dir()
    'Do some other stuff here
    Loop
    [/code]
    Calling Dir() without any paramaters will continue the last search.

    Greets...
    Richard

  • : Hi,
    :
    : I need to access all files of a certain type within a folder. I am currently using FileListBox, setting the pattern to "*.yld" and then using .listcount to see how many files there are.
    :
    : My problem is I came accross a folder with just over 40,000 files in it, and as FileListBox appears to be unsigned 16 bit, the result I got from .listcount was negative.
    :
    : Is there another way of seeing all these files, or is there a 32 bit equivelant of FileListBox out there?
    :
    : Regards
    :
    You can use the method Richard proposed in the other post, or you can tweak the negative number.

    You guess that the control's listcount property is designed to return a 16bit number is probably right. However, 40000 perfectly fits into 16 bits. The problem here is that even though logically the listcount cannot be zero, VB uses signed numbers. For the Integer type this means that VB interprets integers from -32768 to 32767. This is the singed integer. An unsigned integer (which would be the logical thing to use in the case) has a range from 0 to 65535.

    Unfortunately, VB supports only singed integers, which turns the hishest bit into a sign indicator. 0 means the number is positive, 1 means the number negative. This means that the number has only 15 bits.

    The FileListBox control, however, is not made with VB, but probably with C++, and the developers decided to use unsigned integer, since the file count cannot be less than zero. So, they store valuable information in the highest bit.

    Here's how tweaking the number in VB works:
    1. We have to move the number into a long variable in order to be able to accomodate the larger positive number.
    2. Now, if the number is positive, we don't do anything with it. It's ready to use.
    3. If the number is negative, however, we need to discard of the "sign" meaning of the highest bit and use it as part of the number.

    All this is done with one simple line of code.

    Enough theory. Here's the code:

    [code]
    Dim RealCount As Long
    RealCount = FileListBoxControl.ListCount And &HFFFF&
    ' [red] Don't forget to put the ampersand at the end!
    [/red]
    [/code]

    Hope I helped,
    Nikolay Semov

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories