Sign in to follow this  
Followers 0
John-Paul

Sort and Save

2 posts in this topic

Does anyone know the trick to saving an altered CSV file.

I open a CSV file, then I click the sort button (in design phase at moment) and the array is sorted by date value or ListView ID.

Once sorted I want to save the file in the newly sorted order, however the save only saves the original file and not the newly sorted file.

Any ideas, don't want to create an alternative file or rename a file, just want to keep the same file name.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Since it is a CSV file, why do not you just modify it using Autoit directly?

You can load the whole file in a variant, split it at @LF (or @CR or @CRLF as needed) and sort that array. Just make a function that compare correctly the dates or the IDs and use a sorting function that compare lines using that function.

E.g. Comparing function for dates in the fourth field of a CSV array...

#include <date.au3>

Func _Before($sfst, $ssnd)
    Local $afst = StringSplit($sfst, ',')
    Local $asnd = StringSplit($ssnd, ',')
    $afst = $afst[4]
    $asnd = $asnd[4]
    $afst = StringSplit($afst, '/')
    $asnd = StringSplit($asnd, '/')
    Return _DateToDayValue($afst[1], $afst[2], $afst[3]) < _DateToDayValue($asnd[1], $asnd[2], $asnd[3])
EndFunc
Edited by ezzetabi

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0