|
-
Oct 2nd, 2000, 09:42 AM
#1
Thread Starter
Addicted Member
Hi,
Are there any FSObject users that can spare a couple of minutes to help answer the folloing Q.
How would I use the FSObject to sort a number of files in a particular dir, in Date order???.
Any advice will be great.
-
Oct 3rd, 2000, 10:36 AM
#2
Fanatic Member
hmm
I have not tried this...
The first thing that pops up in my head as I read this
was
1. create a list view of these files
2. Display the file and the date as columns
3. Then use the listview sort to sort by the date column
-
Oct 3rd, 2000, 10:48 AM
#3
Thread Starter
Addicted Member
A bit more detail pls...
Could I possibly trouble you to go inyo a bit more detail????
I am a newbie at all this.
-
Oct 3rd, 2000, 01:31 PM
#4
Fanatic Member
ok
just got this...
give me a few .... minutes
-
Oct 3rd, 2000, 02:35 PM
#5
Fanatic Member
ok
Any specific part you want to elaborate on?
1. Get a listView on your form
2. Right-Click on it
3. Go to Column Headers and Insert 2 columns
One might be called File, the other LastModifiedDate
Assume your list is called ListView1, put this code in the
Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
with With ListView1
.SortKey = ColumnHeader.Index - 1
If .SortOrder = lvwAscending Then
.SortOrder = lvwDescending
Else
.SortOrder = lvwAscending
End If
.Sorted = True
End With
That would allow you to sort when you clik either of these
columns when you click on the column header
Now... populate the list view with the files you want to sort... (I don't know whether u did that already or not)
and the functionality is there
What I don't know...
Do you want to do this like I described here
or totally in the background where you would get rid
of all the files in a folder except the 5 most recent
or...
Depending on your answer, there may be more efficient ways to do this...
a little clarification could help immensely
-
Oct 4th, 2000, 02:59 AM
#6
Thread Starter
Addicted Member
Should have made myself clear>>
I want to run this in the background and call it into other Subs i have.
I sort of understand the posting you made before, but I want to run this without any GUI for this command.
-
Oct 4th, 2000, 03:26 AM
#7
transcendental analytic
A solution without FSO, use dir function to retrieve the files in a directory and sort the files with sort shell 
Code:
Sub EnumDir(ByRef edir() As String, path As String)
Dim n As Integer, a As String
a = Dir(path)
Do While Len(a)
ReDim Preserve edir(n)
edir(n) = a
n = n + 1
a = Dir
Loop
End Sub
Sub Sort_shell_Filesbydate(a() As String)
Dim n&, i&, j&, k&, h
n = UBound(a)
k = n \ 2
While k > 0
For i = 0 To n - k
j = i
While (j >= 0) And DateDiff("s", FileDateTime(a(j)), FileDateTime(a(j + k))) > 0
h = a(j)
a(j) = a(j + k)
a(j + k) = h
If j > k Then
j = j - k
Else
j = 0
End If
Wend
Next i
k = k \ 2
Wend
End Sub
Sub Main()
Dim Files() As String, n As Long
EnumDir Files, "C:\"
ChDir ("C:\")
Sort_shell_Filesbydate Files
For n = 0 To UBound(Files)
Debug.Print Files(n)
Next n
End Sub
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
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
|