|
-
Dec 18th, 2004, 01:51 PM
#1
Thread Starter
Banned
list files in a folder?
is a way with standard vb?
Last edited by nareth; Dec 19th, 2004 at 04:00 PM.
-
Dec 18th, 2004, 02:12 PM
#2
Re: list files in a folder?
sure, the Dir() function.
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
casey.
-
Dec 18th, 2004, 02:29 PM
#3
Thread Starter
Banned
Re: list files in a folder?
thanks =)
-
Dec 18th, 2004, 02:44 PM
#4
Thread Starter
Banned
Re: list files in a folder?
is there a way to count the files in the directory without this method?
-
Dec 18th, 2004, 02:49 PM
#5
Re: list files in a folder?
if you mean WITH this method, then here it is.
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
What files do you want to count, if you don't want to use this method?
You could just count them without displaying them.
-
Dec 18th, 2004, 02:50 PM
#6
Thread Starter
Banned
Re: list files in a folder?
with OUT
because im using a dynamic array so it would take long to keep using redim preserve
-
Dec 18th, 2004, 06:57 PM
#7
Frenzied Member
Re: list files in a folder?
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
We miss you, friend...  Rest in Peace, we will take care of the rest of it.
[vbcode]
On Error Me.Fault = False
[/vbcode]
- Silence is the human way to share ignorance
Tec-Nico
-
Dec 19th, 2004, 10:08 AM
#8
Thread Starter
Banned
Re: list files in a folder?
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.
-
Dec 19th, 2004, 11:59 AM
#9
Thread Starter
Banned
Re: list files in a folder?
-
Dec 19th, 2004, 12:13 PM
#10
Re: list files in a folder?
nareth,
Come on, think...
Only redim preserve every one hundreth time or so.
-
Dec 19th, 2004, 12:46 PM
#11
Thread Starter
Banned
Re: list files in a folder?
-
Dec 19th, 2004, 12:58 PM
#12
Re: list files in a folder?
nareth,
Not meaning to be harsh. Just attempting to get you to see the easier way other than doing something everytime.
-
Dec 19th, 2004, 01:06 PM
#13
Thread Starter
Banned
Re: list files in a folder?
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.
-
Dec 19th, 2004, 01:13 PM
#14
Thread Starter
Banned
Re: list files in a folder?
is there anyone whos willing to HELP instead of telling me what todo. i know what im doing
-
Dec 19th, 2004, 01:22 PM
#15
Re: list files in a folder?
because im using a dynamic array so it would take long to keep using redim preserve
It was your idea.
?????
-
Dec 19th, 2004, 01:24 PM
#16
Thread Starter
Banned
Re: list files in a folder?
 Originally Posted by randem
It was your idea.
?????
please delete this post im getting pissed now
-
Dec 19th, 2004, 02:15 PM
#17
Hyperactive Member
Re: list files in a folder?
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
Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White
-
Dec 19th, 2004, 02:51 PM
#18
Re: list files in a folder?
 Originally Posted by nareth
please delete this post im getting pissed now 
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.
-
Dec 19th, 2004, 03:17 PM
#19
Re: list files in a folder?
 Originally Posted by nareth
is there a way to count the files in the directory without this method?
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
is there anyone whos willing to HELP instead of telling me what todo. i know what im doing
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.
kevin
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Dec 19th, 2004, 04:00 PM
#20
Thread Starter
Banned
Re: list files in a folder?
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 -.-
Last edited by nareth; Dec 19th, 2004 at 04:03 PM.
-
Dec 19th, 2004, 06:56 PM
#21
Re: list files in a folder?
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.
-
Dec 20th, 2004, 03:29 AM
#22
Thread Starter
Banned
Re: list files in a folder?
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
-
Dec 20th, 2004, 06:01 AM
#23
Re: list files in a folder?
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
-
Dec 20th, 2004, 06:40 AM
#24
Thread Starter
Banned
Re: list files in a folder?
woka you dont get the situation
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
Last edited by nareth; Dec 20th, 2004 at 06:49 AM.
-
Dec 20th, 2004, 07:04 AM
#25
Re: list files in a folder?
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:
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 loads them dynamically. But it is quick as it redim preserves 500 at a time, and not for EVERY file.
This is what you should use, but you had a go at people suggesting it.
Woka
Last edited by Wokawidget; Dec 20th, 2004 at 07:11 AM.
-
Dec 20th, 2004, 07:10 AM
#26
Thread Starter
Banned
Re: list files in a folder?
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?
-
Dec 20th, 2004, 07:22 AM
#27
Re: list files in a folder?
 Originally Posted by nareth
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.
What memory overhead???
A collection will use slightly more memory that an array, but it has many other benefits.
Woka
-
Dec 20th, 2004, 07:41 AM
#28
Re: list files in a folder?
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
-
Dec 20th, 2004, 08:56 AM
#29
Re: list files in a folder?
 Originally Posted by nareth
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
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.
Cheers.
-
Dec 20th, 2004, 09:24 AM
#30
Thread Starter
Banned
Re: list files in a folder?
i know more than you think rhino =)
-
Dec 20th, 2004, 09:50 AM
#31
Re: list files in a folder?
 Originally Posted by nareth
i know more than you think rhino =)
And I have no doubt about it ...
-
Dec 20th, 2004, 01:29 PM
#32
Banned
Re: list files in a folder?
banning me is the easy way out.
-
Dec 24th, 2004, 06:47 PM
#33
Frenzied Member
Re: list files in a folder?
Huh - Is everyone getting banned or what ??
-
Dec 24th, 2004, 08:01 PM
#34
Re: list files in a folder?
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's cold gin time again ..."
Check out my website here.
-
Dec 26th, 2004, 12:54 PM
#35
Lively Member
Re: list files in a folder?
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
 Originally Posted by vbasicgirl
sure, the Dir() function.
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
casey.
-
Dec 26th, 2004, 01:00 PM
#36
Re: list files in a folder?
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Dec 26th, 2004, 01:09 PM
#37
Lively Member
Re: list files in a folder?
Thanks for the explanation.
RobertXYZ
 Originally Posted by RobertXYZ
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|