|
-
Feb 5th, 2001, 10:25 AM
#1
Thread Starter
New Member
I need to get a list of file names (that I'll probably store in an array) from a determined directory sorted by file name, so I can process them correctly. I could have up to 10,000 files in this directory, so loading the names in an array and sorting them is not the best solution.
Does anybody know a registry setting (files getting sorted as they get dropped inside the directory), an API call or a piece of code that could solve my problem?
I have a couple of proposed solutions but none of them are bullet proof!
1 - Load all the files into an array. Read file by file (go one at a time in the array), until end of array. Load array again with new file names that have been dropped in the folder. Sort array when loaded(once)
2 - Use a file control. Load Filelist, process file, refresh file list.
(kind of slow if more then 5000 files). The refreshing is very slow (0.5
seconds per batch. So I after processing each file, If I want to get a
snapshot of the latest in the folder, I will be wasting too much time!)
Both solutions won't let me "watch" the directory at all times and let me get a snapshot of the latest file list I have. This app is supposed to be a "listener". I will be grabbing the files and process them accordingly. They need to be processed in a certain order (by file name!). After they are processed, they are moved somewhere else!
In the ideal world I would be loading the filelist control or the array at all times(every second, or after each process)... But the sorting will take too long if I do that... I got to process those files faster......
I've tried with arrays... It seems to be slower than using the following example where I used a FileList(for some reason, it's sorting by name by default) control. For a load of 3000 files, it only took 70 milliseconds to
refresh. The reason why I wanted to sort the files before getting a list is because I could use a fast API call (GetFirst()) instead of even getting a list and loading this list somewhere (control or array).
FileList.Path = "c:\new" 'I created 3000 files within this directory
Label1.Caption = GetTickCount 'API call to determine the number of
milliseconds that has elapsed since windows was started
FileList.Refresh
Label2.Caption = GetTickCount 'API call to determine the number of
milliseconds that has elapsed since windows was started
Label3.Caption = Str(Int(Label2.Caption) - Int(Label1.Caption)) 'to see
how many milliseconds it actually too to refresh the control.
Form1.Caption = FileList.ListCount & " files in the directory"
You may be asking yourself!!!! Only 70 milliseconds???? Yeah, but if I have 3000 files (70 milliseconds x 3000 refreshes = 210 seconds or about 3.5 minutes), this 70 milliseconds can make a difference. I still need to add
the overhead of opening and closing the file, passing the file's contents (XML) to a COM+ object, waiting to parse the XML and finally inserting into a database. And if I need to refresh the control 3000 times, my app will
hog!!!
The reason behind my posting is because I will be receiving files (at random times) from 3 different systems. The files being dumped are dependents of
each other, and that's why I need to process them in a certain order. And the file naming convention will determine this dependency. That's the reason
why I need to sort the files by name!!!!
-
Feb 11th, 2001, 03:04 AM
#2
Addicted Member
Try Using The Collections. I Think This Will Work
-
Feb 11th, 2001, 03:22 PM
#3
Member
There is a nice file system object often used in ASP (Active Server Pages) applications. Look it up in the VB help files under:
FileSystemObject Object
You can search for files, directories and directory trees.
-
Feb 11th, 2001, 03:30 PM
#4
Member
' Another solution with a listbox control on a form
' Listbox property 'Sorted' must be true
Option Explicit
Private Sub Command1_Click()
Dim Path As String, FileName As String
' In the property window of List1 set
' property: Sorted = True
Path = "C:\Windows\System"
FileName = Dir("*.*", vbNormal + vbReadOnly + vbHidden) ' Choose the appropriate flags
Do While Len(FileName)
List1.AddItem FileName
FileName = Dir()
Loop
Dim i As Integer
For i = 0 To List1.ListCount - 1
DoSomeThingWithFile List1.List(i)
Next i
End Sub
Private Sub DoSomeThingWithFile(FileName As String)
MsgBox FileName
End Sub
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
|