Results 1 to 7 of 7

Thread: File System Object....

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2000
    Location
    London, UK
    Posts
    137

    Red face

    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.

    join me in the platinum

  2. #2
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    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



  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2000
    Location
    London, UK
    Posts
    137

    A bit more detail pls...

    Could I possibly trouble you to go inyo a bit more detail????

    I am a newbie at all this.
    join me in the platinum

  4. #4
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    ok

    just got this...

    give me a few .... minutes

  5. #5
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    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



  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2000
    Location
    London, UK
    Posts
    137

    Cool 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.


    join me in the platinum

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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
  •  



Click Here to Expand Forum to Full Width