|
-
Mar 9th, 2013, 03:58 PM
#1
Thread Starter
PowerPoster
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?
-
Mar 9th, 2013, 06:36 PM
#2
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
-
Mar 9th, 2013, 07:55 PM
#3
Re: sort file name based date
 Originally Posted by DataMiser
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.
-
Mar 9th, 2013, 08:15 PM
#4
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
|