×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Efficient Directory list

Efficient Directory list

Efficient Directory list

(OP)
Hi,

I'm looking for a way to get a list of files with creation date - sorted by date, most recent first, into a list box.

I have this working at the moment - but it's a bit inefficient.

One of the requirements is that the user must be able to click on a file in the list - and be able to edit it. So the refresh of the list shouldn't be an event the user notices.

The other requirement is that the list should be updatedn "in real time". I've taken this to mean every couple of seconds.

My approach so far has been a file list box to pick up all the file names - insert any changed entries into a listbox complete with date and time retrieved with FileDateTime. Not bad - but if you start inserting/updating items in a listbox the Sorted property is worthless and if I start the list off from scratch each time it flicks around and looks horrible.

So - ideas welcome - Eric? Alt255?

Mike

Mike Lacey
Mike_Lacey@Cargill.Com
Cargill's Corporate Web Site

RE: Efficient Directory list

look at "Dir" function
here are some samples form Help in VB6
-----------------
Dim MyFile, MyPath, MyName
' Returns "WIN.INI" if it exists.
MyFile = Dir("C:\WINDOWS\WIN.INI")

' Returns filename with specified extension. If more than one *.ini
' file exists, the first file found is returned.
MyFile = Dir("C:\WINDOWS\*.INI")

' Call Dir again without arguments to return the next *.INI file in the
' same directory.
MyFile = Dir

' Return first *.TXT file with a set hidden attribute.
MyFile = Dir("*.TXT", vbHidden)

' Display the names in C:\ that represent directories.
MyPath = "c:\" ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While MyName <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName <> "." And MyName <> ".." Then
' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
Debug.Print MyName ' Display entry only if it
End If ' it represents a directory.
End If
MyName = Dir ' Get next entry.
Loop

RE: Efficient Directory list

you can do it with this Function (i send you the example)

Private Function LineInfo(fName As String)
'Get more information about each file
Dim nLength As Long
Dim sSpaces As Long
Dim NewEnt As String
Dim DateFix As String
Dim NewDate As String
'Add File Date
DateFix = Str(FileDateTime(fName))
If Mid(DateFix, 2, 1) = "/" Then
'm1
NewDate = "0" + Mid(DateFix, 1, 2)
If Mid(DateFix, 4, 1) = "/" Then
'm1 d1
NewDate = NewDate + "0" + Mid(DateFix, 3, 4) + Space(2)
If Len(DateFix) < 9 Then
'm1 d1 Midnight
NewDate = NewDate + "12:00:00 AM"
End If
If Mid(DateFix, 9, 1) = ":" Then
'm1 d1 h1
NewDate = NewDate + "0" + Mid(DateFix, 8, 17)
Else
'm1 d1 h2
NewDate = NewDate + Mid(DateFix, 8, 18)
End If
Else
'm1 d2
NewDate = NewDate + Mid(DateFix, 3, 5) + Space(2)
If Len(DateFix) < 9 Then
'm1 d2 Midnight
NewDate = NewDate + "12:00:00 AM"
End If
If Mid(DateFix, 10, 1) = ":" Then
'm1 d2 h1
NewDate = NewDate + "0" + Mid(DateFix, 9, 17)
Else
'm1 d2 h2
NewDate = NewDate + Mid(DateFix, 9, 18)
End If
End If
Else
'm2
NewDate = Mid(DateFix, 1, 3)
If Mid(DateFix, 5, 1) = "/" Then
'm2 d1
NewDate = NewDate + "0" + Mid(DateFix, 4, 4) + Space(2)
If Len(DateFix) < 9 Then
'm2 d1 Midnight
NewDate = NewDate + "12:00:00 AM"
End If
If Mid(DateFix, 10, 1) = ":" Then
'm2 d1 h1
NewDate = NewDate + "0" + Mid(DateFix, 9, 17)
Else
'm2 d1 h2
NewDate = NewDate + Mid(DateFix, 9, 18)
End If
Else
'm2 d2
NewDate = NewDate + Mid(DateFix, 4, 5) + Space(2)
If Len(DateFix) < 9 Then
'm2 d2 Midnight
NewDate = NewDate + "12:00:00 AM"
End If
If Mid(DateFix, 11, 1) = ":" Then
'm2 d2 h1
NewDate = NewDate + "0" + Mid(DateFix, 10, 17)
Else
'm2 d2 h2
NewDate = NewDate + Mid(DateFix, 10, 18)
End If
End If
End If
LineInfo = NewDate + Space(2)
'Add File Length
nLength = Len(Str(FileLen(fName)))
sSpaces = 10 - nLength
LineInfo = LineInfo + Space(sSpaces) + Str(FileLen(fName))
List1.AddItem LineInfo
End Function

Eric De Decker
vbg.be@vbgroup.nl
Visual Basic Center

RE: Efficient Directory list

Mike, it sounds like you've got it made (except for the problem with the horrible update flicker). Why not store the results of your file search in an invisible object, compare the contents against your list box and only refresh the list box when there have been changes? It would eliminate the flicker and keep the program workings behind the scenes, where we like them.
I'd show you a quick way to do this but I would surely draw the ridicule of the programming "purists" out there.

Purity is in the head, functionality is in the hand.

RE: Efficient Directory list

(OP)
Alt - that's actually what I did <smile> probably in a way that would make the real programmers feel ill.

I like Eric's solution better though (it's prettier) so I'm going to use that.

Mike

Mike Lacey
Mike_Lacey@Cargill.Com
Cargill's Corporate Web Site

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close