![]() |
Forum Index : Microcontroller and PC projects : Is there any way to print DIR$ sorted?
Author | Message | ||||
Amnesie Guru ![]() Joined: 30/06/2020 Location: GermanyPosts: 675 |
Hello all, I'm spending the whole day wrapping my head around this problem. I am using the latest PicoMiteVGA Firmware. the Files command allows to list the files sorted by name, for example. But this command isn't available in the program itself. BUT there is the DIR$ command. It does just what I want, but with a big problem, it ALWAYS sort the DIRs by the date or time of creation. I've tested this many times with folders. To make things clear, I've freshly created folders one after one with this scheme: first I created folder named "1" then ... "7" ..10 ..22 ..5 Background: I trying to save a listing in an array like this: Dim String directory(200), fileName Dim Integer foundFiles f$=Dir$("*",Dir) Do While f$ <> "" Inc foundFiles fileName= f$ directory(foundFiles)=fileName f$=Dir$() Loop 'print the array For n=1 To 30 Print directory(n) Next n Edited 2025-07-25 21:41 by Amnesie |
||||
twofingers![]() Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1593 |
Hi Daniel, but there is a SORT command. You'll learn how to use it in FM (@javavi). Or look at the old Klingon FM (for VT100), where it's done a little differently. Regards Michael The central procedure was called Sub GetFList( by Vadim. ![]() I think you can do it! Edited 2025-07-25 22:23 by twofingers causality ≠ correlation ≠ coincidence |
||||
Amnesie Guru ![]() Joined: 30/06/2020 Location: GermanyPosts: 675 |
Hey, I can't thank you enough for pointing me in this direction! I've tried to isolate the code snipped and it works perfectly! Now there is only one task left: to UNDERSTAND it ![]() ![]() For everyone who may need this code snippet: Dim string TMP$ Const RMAX=199 'Max number of Records in File List (255 max) Dim string FList$(RMAX) LENGTH 63 Dim integer RQt,DQt,FQt,S,i TMP$=Dir$("*",DIR) Do While TMP$<>"" If RQt=(RMax-1) Then Exit Do Inc RQt: Inc DQt FList$(RQt)="/"+TMP$ TMP$=Dir$() Loop Sort FList$(),,2,1,RQt For n=1 To 30 'change here for max listing... Print FList$(n) Next n Thank you again for this fast response! This helped me a lot! Greetings Daniel Edited 2025-07-25 22:37 by Amnesie |
||||
twofingers![]() Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1593 |
Really? That shouldn't work! Something's missing! I think—at a quick glance—you're only reading directories and not sorting yet. But I don't want to complain if that's enough for you. ![]() Michael Hint: To sort the file properties, you need a numeric index(rMax) array. Edited 2025-07-25 22:52 by twofingers causality ≠ correlation ≠ coincidence |
||||
Amnesie Guru ![]() Joined: 30/06/2020 Location: GermanyPosts: 675 |
Uhmm... I don't know but it works. I tried it with different folders. I thought: Sort FList$(),,2,1,RQt does the sorting... And the printing of the array does give back a sorted array of strings... ![]() ![]() For n=1 To 30 'change here for max listing... Print FList$(n) Next n This gives me a perfectly sorted list... What I am missing? May I have found a bug (to my favour?) ![]() Greetings Daniel Edited 2025-07-25 23:08 by Amnesie |
||||
twofingers![]() Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1593 |
Actually, reading the file list works in two steps: 1. Reading directories. 2. Reading file names. I haven't tested why it seems to work for you. To sort the file properties, you need a numeric index(rMax) array. And the corresponding numeric arrays with the file properties. I assumed you also wanted to be able to sort by file size and date. Michael causality ≠ correlation ≠ coincidence |
||||
Amnesie Guru ![]() Joined: 30/06/2020 Location: GermanyPosts: 675 |
Ah, maybe here comes the missunderstanding! I am not interested in sorting file properties at all. I am only interested in the name of the folder (or file). I just wanted a sorted list of strings, If you will. But thanks for this explanation! I am working on a "journal / diary" application with graph stats and so on... this is why I was in need of sorting it and don't care about file properties: ![]() Greetings Daniel Edited 2025-07-25 23:35 by Amnesie |
||||
twofingers![]() Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1593 |
Hi Daniel, sehr schön! Very nice! ![]() Why I'm surprised: normally, TMP$=Dir$("*",DIR) should only read folders.To read files (names), you need TMP$=Dir$("*",FILE) .This just in case your method doesn't work. ![]() Edited 2025-07-25 23:55 by twofingers causality ≠ correlation ≠ coincidence |
||||
Amnesie Guru ![]() Joined: 30/06/2020 Location: GermanyPosts: 675 |
Ah! Now I completly understand what you mean! TMP$=Dir$("*",DIR) should only read folders. Yes, yes it does! It only reads folders. What I initially wanted to say is the following: Thanks to your hint with Vadims FM, I sucessfully cut out the code snippet and it works AS is in this example (only for DIR, of course). But I implemented it already in my program, the crucial hint from you, was the SORT command I wasn't aware of. I already adapted it in my program, since it was only one line to add! I am completely aware of the fact, that there are three parameters: DIR, FILE, ALL Typischer Fall von einander vorbeigeredet würde ich sagen ![]() Greetings Daniel |
||||
twofingers![]() Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1593 |
Yes, if I had understood correctly right away (no need to sort the file properties), then I could have given you simpler examples, like the early versions of FM or my NSA . Something else: I was just thinking today (last night) whether we shouldn’t have a central thread with examples for every command/function that go beyond the manual’s explanation. It doesn’t need to be sorted at first, and could later be incorporated into the FOTS. I believe there are complex, very useful functions that users avoid because their usage isn’t obvious. Examples from my subjective point of view: Dir$(), many of the MATH functions, Play Sound 1,,U,, etc. Michael causality ≠ correlation ≠ coincidence |
||||
Amnesie Guru ![]() Joined: 30/06/2020 Location: GermanyPosts: 675 |
Hi Michael, I am also working on this and have created same examples myself. The biggest one is how to use the line command for drawing an autoadjustable and autoscaling graph (which I needed for my geiger counter). I already worte a whole explanation of this - but at this point in time it is only german language. I still have to translate it. Also some Math examples I tested and wrote example programs for it (and found bugs, which Peter fixed). If you are curious, here is at least one whole complex example: Linie bis Liniendiagramm.pdf Be warned, this is a WHOLE complex example on 19 pages! I have more of those writte. But as said, have to translate them and error-check them again. Greetings Daniel Edited 2025-07-26 01:59 by Amnesie |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 5091 |
Michael, +1 Some of my programs make use of MATH array functions, to replace nested for-next loops. These could educate others. Like use of math array multiplication to calculate linear interpolated values (cpnvert 16x12 thermal camera to a 63x47 pixel picture). Another example is the use of the math standard deviation funtion that is mathmatically identical to calculating the rms value of an array of samples. Smart things, speed up interpreted basic. Volhout Edited 2025-07-26 02:08 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
javavi![]() Guru ![]() Joined: 01/10/2023 Location: UkrainePosts: 507 |
Hello all, The SORT command is wonderful, it sorts everything quickly and even creates an index array of sort order. It's just a pity that there is no corresponding command in MMBASIC that could sort an array by this index array. At the same time, so that it does not use additional memory, such as an intermediate array for copying. In my FM program, I had to invent an algorithm for laying out lines in a list by index array myself, since there was limited RAM. But it is clear that this algorithm in MMBASIC works slower than it could work if it were in the form of a built-in BASIC command. |
||||
Amnesie Guru ![]() Joined: 30/06/2020 Location: GermanyPosts: 675 |
Harm, 100% agreed. I am not that great in programming BASIC and always in the need of help to understand the examples in the manual (I do always try to read / search the manual first) but sometimes there are commands which are not that trivial to understand or to implement; there is often more needed to "show" how things work in MMBASIC. In this community there are a lot of people who have decades of knowledge in BASIC (and other programming lang.). I am relativly "new" to this and came from C and Python. If I see some of your complex works like the thermal camera or the mains monitor with FFT involved or even interpolation, my brain just shuts up. It is impressive what can be done. There is so much to lern. I also try to document my learning process by saving and creating my examples and write some pages about it. Not something like interpolation or FFT, but simpler things ![]() I would LOVE to see some examples database of ALL functions / commands. This would help a lot. Greetings Daniel |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |