[Issue] Dir: random sorting with Linux

Keyboard macros or custom scripts

[Issue] Dir: random sorting with Linux

Postby Bidouille » Mon Mar 16, 2015 6:23 pm

Hello,
A folder contains 5 files:
  • chat001.jpg
  • chat002.jpg
  • chat398.jpg
  • chat401.jpg
  • chat690.jpg
If I execute this code:
Code: Select all   Expand viewCollapse view
Sub Main
   path = "~/test/"
   myFile = Dir(path & "*")
   While myFile <> ""
      url = ConvertToUrl(path & myFile)
      result = result + url + chr(10)
      myFile = Dir
   Wend
   msgbox result
End Sub

The result is sorted non alphabetically.
Image
Tested with AOO 4.1.1 and Debian 7 x64

Could you confirm the bug?
Last edited by Bidouille on Thu Mar 19, 2015 11:30 am, edited 1 time in total.
User avatar
Bidouille
Volunteer
 
Posts: 289
Joined: Mon Nov 19, 2007 10:58 am
Location: France

Re: Dir: random sorting with Linux

Postby Villeroy » Mon Mar 16, 2015 10:24 pm

This is not a bug. The order of files queried from the file system is up to the file system. If you want a sorted list then sort it.
Same with this code:
Code: Select all   Expand viewCollapse view
srv = createUnoService("com.sun.star.ucb.SimpleFileAccess")
dirlist = srv.getFolderContents("file:///home/user/test", True)
msgbox join(dirlist, Chr(10))
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27290
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Dir: random sorting with Linux

Postby Bidouille » Tue Mar 17, 2015 10:30 am

Villeroy wrote:The order of files queried from the file system is up to the file system.

Despite several attempts in a console with ls command, I have not found in what order was sorted files.
_dir_linux.gif

Villeroy wrote:If you want a sorted list then sort it.

With Windows, Dir returns files list correctly.
User avatar
Bidouille
Volunteer
 
Posts: 289
Joined: Mon Nov 19, 2007 10:58 am
Location: France

Re: Dir: random sorting with Linux

Postby RoryOF » Tue Mar 17, 2015 12:02 pm

@Bidouille: I think you need to look at the file save time seconds to get the exact order of the sorted files. In your screenshot Chat398.jpg, chat401.jpg and chat002.jpg are all shown with date/time of 16/03/2015 15:58, but they may all differ in the seconds place, which you do not display but which a time based sort will take into account.

As Villeroy points out, it is logical that your subroutine returns the files in the order the operating system filehandler sees them. Unless there are API parameters to cause a directory query to be returned in sorted order (I don't know - I haven't looked), your best approach may be to read the directory names into an array and call a sort routine.
Apache OpenOffice 4.1.7 on Xubuntu 18.04.3 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 29744
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Dir: random sorting with Linux

Postby acknak » Tue Mar 17, 2015 2:37 pm

try ls -U (unsorted)

It's possible that the names are returned in the order that they appear in the directory on disk, which, as Villeroy pointed out, could be anything.
AOO4/LO5 • Linux • Fedora 23
User avatar
acknak
Moderator
 
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Dir: random sorting with Linux

Postby Bidouille » Wed Mar 18, 2015 12:41 pm

OK, I resume:
Basic Windows = Dir
Basic Linux = ls -U

So, it would be better that:
Basic Linux = ls

RFE reported: https://bz.apache.org/ooo/show_bug.cgi?id=126186
User avatar
Bidouille
Volunteer
 
Posts: 289
Joined: Mon Nov 19, 2007 10:58 am
Location: France


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 1 guest