Results 1 to 4 of 4

Thread: sort file name based date

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,932

    sort file name based date

    in dir c:\mydir\ have a variuos .txt file(only this format)

    the single file name have this structure:

    aaa0_01-05-2013
    aaa1_02-05-2013
    aaa1_02-06-2013
    aaa1_01-05-2013
    aaa2_01-05-2013

    i need to store the file name in to an array and loop it based aaa(x) and date

    how to?

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: sort file name based date

    If you want you files sorted properly using a date in the filename then you need to use a different date format. Year month day.

    As for the other question I can't really tell what you are asking.

    What does this mean
    loop it based aaa(x) and date

  3. #3
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: sort file name based date

    Quote Originally Posted by DataMiser View Post
    If you want you files sorted properly using a date in the filename then you need to use a different date format. Year month day.

    As for the other question I can't really tell what you are asking.

    What does this mean
    Code:
    loop it based aaa(x) and date
    It does sound funny haha but he wants to sort the filename (before date) in order and then also the date (after filename) in order.

    So,
    Code:
    aaa0_01-05-2013
    aaa1_02-05-2013
    aaa1_02-06-2013
    aaa1_01-05-2013
    aaa2_01-05-2013
    Becomes
    Code:
    aaa0_01-05-2013
    aaa1_01-05-2013
    aaa1_02-05-2013
    aaa1_02-06-2013
    aaa2_01-05-2013
    This would be if 01-05-2013 is dd/mm/yyyy.
    Hopefully i understand this right, I don't feel like making a code to sort this either!

    You could sort FileName first, then Year, then Month, the Day. Also an easier way would be to use a 2D array.

    MyArr(0,0) = aaa0_01-05-2013
    MyArr(0,1) = aaa1_01-05-2013
    MyArr(0,2) = aaa1_02-05-2013
    MyArr(0,3) = aaa1_02-06-2013
    MyArr(0,4) = aaa2_01-05-2013

    MyArr(1,0) = aab0_01-05-2013
    MyArr(1,1) = aab1_01-05-2013
    MyArr(1,2) = aab1_02-05-2013
    MyArr(1,3) = aab1_02-06-2013
    MyArr(1,4) = aab2_01-05-2013

    Use Split() to split filename and date, using "_" delimiter.
    Then you can use Split() again and use "-" as delimiter and sort By Year, Month, Day. Or you could convert to date and use DateDiff() or create a similar function.

  4. #4
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: sort file name based date

    You might also consider using an MSHFlexGrid and the custom sort feature instead of a ListBox or something. You could also use a hidden one then extract the sorted data to an array.

    Or you could load up a fabricated ADO Recordset with two fields: FileName and a reformatted FileName and sort on the second field.

    Assuming MM-DD-YYYY here:
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by dilettante; Mar 9th, 2013 at 08:19 PM.

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