Click to See Complete Forum and Search --> : The most efficient way to search a file


enigmaos
October 12th, 2001, 11:30 AM
1) There are about 100,000 files in a directory, and I need to know the most efficient way to find a file in that directory.

2) Also, I'm trying to determine if directory A has over 100,000, then create directory B and put files in that directory, so that file search will not be slowed down. Then if directory B has over 100,000 files in it then create directory C, and on, and on.

Any good ideas/suggestions??

Thanks!

enigmaos@yahoo.com

DSJ
October 12th, 2001, 11:58 AM
When it comes to manipulating files and folders they FileSystemObject comes in pretty handy... you'll need a reference to the Microsoft Scripting Runtime (SCRRUN.DLL)...


private Sub Command1_Click()
Dim fs as FileSystemObject
Dim f as Folder

set fs = new FileSystemObject
set f = fs.GetFolder("C:\Windows")

MsgBox "Folder " & f.Name & " has " & f.Files.Count & " files."

If fs.FileExists("C:\WINDOWS\WINSOCK.DLL") then
MsgBox "Winsock.Dll is in directory"
else
MsgBox "Winsock.dll isn't in directory"
End If

If f.Files.Count > 20 then
fs.CreateFolder ("C:\SomeNewFolder")
MsgBox "new Folder Created."
End If

End Sub

Green_Beret
October 15th, 2001, 05:00 AM
You can try using the APIs FindFirstFile and
FindNextFile

Regards,
Saurabh.