Author Topic: Reading Directories and Files without SHELLing out  (Read 5884 times)

0 Members and 1 Guest are viewing this topic.

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: Reading Directories and Files without SHELLing out
« Reply #15 on: September 16, 2019, 09:12:46 am »
One last question for this neat new tool bag trick.

When directories and files are found.  Will they always be in sorted order ?

I created a test directory with files and directories created out of order.  Running the program
everything became sorted properly.

I expected the list to be as found (out of order in directory) not sorted.

I can take advantage of this.  If this will always be the case.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Reading Directories and Files without SHELLing out
« Reply #16 on: September 16, 2019, 10:04:19 am »
To be honest, I don’t know.  Usually you can change sorting order by parameter (sort by name, or size, or type), and I don’t remember if I specified for this to sort by name, or if it’s just doing it by default.  (In which case, the default sort method might not be the same all the time.). I’ll have to dig back into my own code later, and sort out how/if it’s handling sorting for us.

It’s a great question; I just don’t have a great answer for it, at the moment.  😳
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Reading Directories and Files without SHELLing out
« Reply #17 on: September 16, 2019, 10:18:58 am »
I think (but I'm not sure) that under Linux I got output that was not alphabetized. Some Linux users would have to try that. I shut down the Linux computer because I was using an old snail with Linux disguised as a computer ...

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Reading Directories and Files without SHELLing out
« Reply #18 on: September 16, 2019, 10:55:05 am »
It *does* get the file_size for us; we just never return it anywhere to make use of it:
thats odd, when I tried storing and printing the file size earlier(when I made that post) it only showed '0' for all file sizes.. thats why I thought it wasn't working. In fact it does show file size now.. very odd. I sit corrected.


*some how a /code was stuck in my post... must have missed it when I made the quote. all fixed.
« Last Edit: September 16, 2019, 11:53:32 am by Cobalt »
Granted after becoming radioactive I only have a half-life!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Reading Directories and Files without SHELLing out
« Reply #19 on: September 16, 2019, 11:36:13 am »
thats odd, when I tried storing and printing the file size earlier(when I made that post) it only showed '0' for all file sizes.. thats why I thought it wasn't working. In fact it does show file size now.. very odd. I sit corrected.

I'd say that was the same issue with it not sorting directories and folders for you.  The version I posted last fixed that issue as well, so you shouldn't have a problem with either from now on.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
Re: Reading Directories and Files without SHELLing out
« Reply #20 on: September 17, 2019, 09:43:27 am »
The 'order' of the returned files is determined by the file system driver, and tends to be a reflection of how things are organised in the file system data structures.

In short, they're in absolutely no order at all.

You'll need to read all the items then sort them yourself by whatever parameter you want.