Geovanny1974
Geovanny1974

Reputation: 99

Best way to know if a folder has specified file types

I have a loop procedure in VB6 which explores all the folders from a specified file path. I then need to know if each detected folder contains MP3 files. I don't want to use the dir command because it takes up a lot of resources. I've tried doing this using FSO, APIs, etc, but I can't find a solution.

Thanks for any help.

Upvotes: 0

Views: 336

Answers (2)

Bob77
Bob77

Reputation: 13267

VB6's Dir$() function is a pretty light wrapper on FindFirstFile and friends. I'm not sure why you think the FSO would be any lighter or faster.

The biggest serious limitations of Dir$() are that it is an ANSI function and it cannot be "interrupted" by a second search while one is already in progress without resetting the state of the first search.

What does "takes up a lot of resources" mean anyway?

I posted a Class wrapping the process at DirLister lightweight Dir() wrapper.

Upvotes: 4

Chibueze Opata
Chibueze Opata

Reputation: 10054

Have you tried the FindFirstFile API function? It should be your best shot. There's a C# example at codeproject A Faster Directory Enumerator

The VB signature goes like this:

<DllImport("kernel32.dll", CharSet := CharSet.Auto)> _
Private Shared Function FindFirstFile(ByVal lpFileName As String, ByRef lpFindFileData As WIN32_FIND_DATA) As IntPtr
End Function

Here's a sample VB implementation http://www.ask-4it.com/how-to-use-findfirstfile-win32-api-from-visual-basic-code-2-ca.html

You can also find a nice microsoft article on usage of the API here.

Upvotes: 0

Related Questions