Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Another problem using GetFirstFile() - re order

Author
Message
Battoad
AGK Developer
17
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 11th Feb 2016 14:31
I have a folder and lets say it contains files A1animal.txt through to A15animal.txt

When I use GetFirstFile(), and it has already been stated that this gets the Last file not the First, it actually gets A9animal.txt whereas I was expecting to get A15animal.txt.

I realise that A1 comes 1st in a certain sequence and assume A11 is coming 2nd and A12 3rd etc but how do I get A15animal.txt by using GetFirstFile() when it is an unknown value now somewhere in the middle of a list.
(note: the file name e.g A15animal.txt will vary depending upon what is MY LAST file name in the folder.

Thanks for any pointers.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 11th Feb 2016 14:38
Read the entire list of filenames into an array of String, then you can sort them, search through them, or do whatever you like. Boom!
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Battoad
AGK Developer
17
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 11th Feb 2016 14:43
Brilliant, thanks CJB, don't know why I didn't think of that. It seams so strange that Windows lists files in 1 sequence and AppGameKit reads them in a different sequence, unless of course Windows makes an adjustment to alter the way it displays.
Anyway I know your method will work so thanks again.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 11th Feb 2016 17:21
It might be reading them in creation order, rather than filename order.
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 11th Feb 2016 18:47
Quote: "It might be reading them in creation order, rather than filename order."


I think it's either that or last modified. It's just a command to start parsing through the files in a folder.
Battoad
AGK Developer
17
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 11th Feb 2016 18:52 Edited at: 11th Feb 2016 19:31
Hi Mobiius, & whoops, DA, missed in overlap:
Quote: "It might be reading them in creation order, rather than filename order."


In an earlier thread Paul posted this:
Quote: "the folders are read in alphabetical order but are placed in a linked list, which reverses the order when they are read back out. I won't change the functionality of the existing command, but I may add an optional parameter to sort the results differently in future"


I still think it is a command which desperately needs parameters which may be added as 1st read parameter, 2nd read parameter etc for when earlier parameters are equal and obviously with standard defaults.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 11th Feb 2016 19:23
i think this will be fixed in the release coming out this month

Sign up for NaGaCreMo!
Battoad
AGK Developer
17
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 11th Feb 2016 19:36
Hi blink0k, do you know something?

Quote: " I may add an optional parameter to sort the results differently in future"

This sounds long term to me but I hope you are right. I seem to be adding more and more workarounds to my projects for 1 reason or another but at the same time I want Paul to know from me that he's done and doing a fantastic job. Thanks.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 13th Feb 2016 22:02
Also, to make sure that the files sort in the order you want (1 followed by 2, etc.), you should zero pad the numbers and then any text sort will handle it properly.
e.g. A01animal.txt, A02animal.txt through to A15animal.txt

Make sure to use zero and not the letter O.
Cheers,
Ancient Lady
Battoad
AGK Developer
17
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 2nd Mar 2016 12:03
Hi Ancient Lady, first an apology for not responding to your earlier post, to be honest I missed it. I had put this problem to the back in the hope and anticipation that the release of version 2.0.17 might include some extra parameters for sorting first and next etc.
However this didn't happen so I was just checking back and noticed your suggestion. I have since found this by far the easiest way forward for me as it was relatively easy to add the zero where necessary in the file name, and it lists files as I would now expect, listing the last file first.
I did put files in an array and attempted to sort but couldn't get what I needed, possibly because I am using strings and not integers, just not sure.
Anyway the bottom line is by padding with a zero works so thank you very much for posting.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 2nd Mar 2016 21:17
i had a lot of problems with sorting until batvink pointed out that all arrays have a zero element (which most people don't use). When you sort, that zero element can appear further down in the array, which is not what people expect so if you want to sort the array you have to manage the zero element

Login to post a reply

Server time is: 2024-11-25 10:39:56
Your offset time is: 2024-11-25 10:39:56