is a way with standard vb?
Printable View
is a way with standard vb?
sure, the Dir() function.
casey.Code:Dim F As String
F = Dir$("C:\*.*", vbNormal Or vbArchive Or vbReadOnly Or vbSystem Or vbHidden)
Do While LenB(F) > 0
Debug.Print F
F = Dir$
Loop
thanks =)
:wave:
is there a way to count the files in the directory without this method?
if you mean WITH this method, then here it is.
What files do you want to count, if you don't want to use this method?Code:Dim F As String
Cnt = 1
F = Dir$("C:\*.*", vbNormal Or vbArchive Or vbReadOnly Or vbSystem Or vbHidden)
Do While LenB(F) > 0
Debug.Print F
F = Dir$
Cnt = Cnt + 1
Loop
Debug.Print Cnt
You could just count them without displaying them.
with OUT
because im using a dynamic array so it would take long to keep using redim preserve
What is wrong about using redim preserve? Anyway... If you don't want to do that, then use this:
Code:Dim strFile As String
Dim colFiles As Collection
Set colFiles = New Collection
strFile = Dir$("C:\*.*", vbNormal Or vbArchive Or vbRedOnly Or vbSystem Or vbHidden)
Do While LenB(strFile) > 0
colFile.Add strFile
strFile = Dir$
Loop
'.... Some other code here, you use the files.
'The count of the number of files will be colFile.Count
Set colFile = Nothing
you dont get it.
when in the loop and i use redim preserve evrytime inside the loop on each file it would be very slow.
API?
anyone?
nareth,
Come on, think...
Only redim preserve every one hundreth time or so.
im asking something
nareth,
Not meaning to be harsh. Just attempting to get you to see the easier way other than doing something everytime.
look there could be 1000 files in this folder or even one million. i just need the fastest way if you like it or not.
is there anyone whos willing to HELP instead of telling me what todo. i know what im doing :wave:
It was your idea.Quote:
because im using a dynamic array so it would take long to keep using redim preserve
?????
please delete this post im getting pissed now :mad:Quote:
Originally Posted by randem
dude you need to chill, he was only trying to help out. if your not going to accept other peoples suggestions when you ask a question then i think you need to reconsider posting in the first place
You should really chill off, man. When you feel like doing something then look at the sample by Randy Birch that demonstrates how to use FindFirstFile(), FindNextFile() api functions.Quote:
Originally Posted by nareth
Quote:
Originally Posted by nareth
Code:Private Sub Form_Load()
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("c:\")
Set fc = f.Files
Debug.Print fc.Count
End Sub
I got your back on this nareth. You ask a question and should get an answer, not question about why you need to do it or possibly better ways to do it. Unless you explain your project fully, none here can give you a better way because they can't see the big picture. But I think that most ppl here, are genuinely trying to help, and sometimes a little patience is cool.Quote:
is there anyone whos willing to HELP instead of telling me what todo. i know what im doing
kevin
thank you kebo, you are the only person along with vbasicgirl that really helped me out =)
and its not that i got pissed because he tried to help me. i see him posting rubbish all time -.-
Just out of curiosity, nareth: did you bother looking at the sample project from that link I posted? The thing is that FSO is nothing more than Windows API wrapper and is noticeably slower that the source plus you have no control over results it's outputting. It's easy enough to use (no doubt about that) but why not learn how to use the source itself and have full control over entire process ???
Same thing applies to CommonDialog, SysInfo and some other controls available in VB ...
Best regards.
the api would be the same as:
Dim F As String
Cnt = 1
F = Dir$("C:\*.*", vbNormal Or vbArchive Or vbReadOnly Or vbSystem Or vbHidden)
Do While LenB(F) > 0
Debug.Print F
F = Dir$
Cnt = Cnt + 1
Loop
Debug.Print Cnt
Nareth, Tec-Nico gave you a perfect example using a collection of what you needed to use.
There is NO NEED what so ever to start getting nasty with people who are trying to help you. If you are using a dynamic array, then you are doing it "wrong" and there is much better coding, like people suggested!!!
You clearly do NOT know what you're doing if your using dynamic arrays. There are much better methods.
Maybe they are essential to your app and maybe it's something that you cannot change. If this is the case then explain so. don't get nasty with users!
People are ONLY trying to help you, can you not see that. Plus you really need to start giving more details in your responses.
Woka
woka you dont get the situation :wave:
i just asked how i could get the file count a DIFRENT way and poeple started to telling me what todo i only asked a simple question.
im FORCED to do it with a dynamic array for speed issues.
guess i would loop trough files first to count and then redim the dynamic array and laod the files :)
Well explain that then clearly.
Why not use a collection though?
You can load the files in a collection, and then do:
Or you can do what Random suggested which would be:Code:colFiles.Count
This loads them dynamically. But it is quick as it redim preserves 500 at a time, and not for EVERY file.Code:Dim strFile As String
Dim strFiles() As String
Dim lngIndex As Long
strFile = Dir$("C:\*.*", vbNormal Or vbArchive Or vbReadOnly Or vbSystem Or vbHidden)
ReDim strFile(0) As String
lngIndex = -1
Do While LenB(strFile) > 0
lngIndex = lngIndex + 1
If lngIndex = UBound(strFiles) Then
ReDim Preserve strFiles(lngIndex+500) As String
End If
strFiles(lngIndex)=strFile
strFile = Dir$
Loop
ReDim Preserve strFiles(lngIndex) As String
This is what you should use, but you had a go at people suggesting it.
Woka
it would make memory overhead as im using a pretty big module class
isnt it faster to first count hte files with the loop and then redim and then loop again?
No, it wouldn't. Try it. I don't think anyways.Quote:
Originally Posted by nareth
What memory overhead???
A collection will use slightly more memory that an array, but it has many other benefits.
Woka
Also, using API functions to get the filenames, instead of Dir(), is WAY faster. Dunno what they are though...do a search on this forum for "find and fiels and API"
WOOF
That's an interesting opinion ... Just wonder: do you completely understand, nareth, the difference between using Windows Source (aka Windows API functions) and functions built into VB IDE ? If not then you should ask for a help - there are plenty of resources here and out there.Quote:
Originally Posted by nareth
Cheers. :wave:
i know more than you think rhino =)
And I have no doubt about it ...Quote:
Originally Posted by nareth
banning me is the easy way out.
Huh - Is everyone getting banned or what ??
Some other ideas I didn't see mentioned. Either way, you can get the file count and ReDim your array once based on that, rather than using ReDim Preserve.
(1) Use the FSO and the Count method of the Files collection for the given Folder.
(2) Use the FileListBox (Visible = False, if desired), and use the ListCount property.
It is with much interest that I tried and studied your code.Since I try
to understand your code my question is :
What means LenB ? When I replace the B by any other letter
I obtain an error message.
My VB6 books do not mention a Len(B) function.
Can you explain ?
Thanks
Robert XYZ
Quote:
Originally Posted by vbasicgirl
LenB() is a function that gets the length of the variable that is passed to it
in bytes instead of characters. It is faster then Len. To get the syntax press
F2 and search for LenB or hit F1 for the definition.
Thanks for the explanation.
RobertXYZ
Quote:
Originally Posted by RobertXYZ