Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: [1]
  Reply  |  Print  
Author Topic: os.path.dirsort() rather slow...?  (Read 8271 times)
David H.
Posts: 158


« on: November 22, 2010, 01:34:36 pm »

FYI,

I was just doing some testing with the File Manipulation Functions using v2.21.10 on Windows. I used the sample function below to get a sorted directory listing of a network drive. The network drive has 78 directories and 185 files. With sorting disabled the timings were:-

1 2010-11-22 12:26:08.299
2 2010-11-22 12:26:08.299
3 2010-11-22 12:26:08.612

With sorting active:-

1 2010-11-22 12:29:32.711
2 2010-11-22 12:29:32.726
3 2010-11-22 12:29:47.426

Seems rather a long time to sort so few items... For comparison, a dir /os command returns a sorted list instantly.

David


Code
  1. FUNCTION showDir(path)
  2.  
  3.  
  4.    DEFINE path STRING
  5.    DEFINE child STRING
  6.    DEFINE handle INTEGER
  7.  
  8.    IF NOT os.Path.exists(path) THEN
  9.       RETURN
  10.    END IF
  11.    DISPLAY "[", path, "]"
  12.    DISPLAY "1 ",CURRENT
  13.    CALL os.Path.dirfmask(1+2+4)
  14.    DISPLAY "2 ",CURRENT
  15.    CALL os.Path.dirsort("size",1)
  16.    LET handle = os.Path.diropen(path)
  17.    DISPLAY "3 ",CURRENT
  18.    WHILE handle > 0
  19.       LET child = os.Path.dirnext(handle)
  20.       IF child IS NULL THEN EXIT WHILE END IF
  21.       DISPLAY os.Path.join(path,child)
  22.    END WHILE
  23.    CALL os.Path.dirclose(handle)
  24.  
  25. END FUNCTION
  26.  

Sebastien F.
Four Js
Posts: 509


« Reply #1 on: November 23, 2010, 03:02:04 pm »

Hello David,

1) I wonder that you are still using 2.21, please move to 2.30 (ask support to help you).
See this:
https://4js.com/en/support/issue/?id=16458
=> Not fixed in 2.21, fixed in 2.30.

2) os.Path.dirsort() is slow on Windows, this is a known problem, we must have a look.

Seb
David H.
Posts: 158


« Reply #2 on: November 24, 2010, 01:35:00 pm »

Hi Seb,

RE: 1) Yes I had already noticed the bug with sorting on file times and that is was fixed in v2.30...!

It is a common requirement for us to work with a subset of the files in a directory (i.e. "*.xml"). As a potential feature request it would be nice if a wildcard filter could be setup to alter the range of files returned by os.Path.dirNext(), i.e:-


    CALL os.Path.dirfmask(1+2+4) #filter file types
    CALL os.Path.filter("*.xml")  # filter range of files returned
    CALL os.Path.dirsort("mtime",1) #sort the files by date modified
    LET handle = os.Path.diropen(path)
    etc

Sebastien F.
Four Js
Posts: 509


« Reply #3 on: November 25, 2010, 10:50:43 am »


It is a common requirement for us to work with a subset of the files in a directory (i.e. "*.xml"). As a potential feature request it would be nice if a wildcard filter could be setup to alter the range of files returned by os.Path.dirNext(), i.e:-

    CALL os.Path.dirfmask(1+2+4) #filter file types
    CALL os.Path.filter("*.xml")  # filter range of files returned
    CALL os.Path.dirsort("mtime",1) #sort the files by date modified
    LET handle = os.Path.diropen(path)
    etc


I have created an enhancement record: #19081
Thanks for the idea.
Seb
David H.
Posts: 158


« Reply #4 on: November 30, 2010, 12:06:31 pm »

On the subject of enhancements, a function to return in advance the count of files returned by dirNext() would be useful too...
Sebastien F.
Four Js
Posts: 509


« Reply #5 on: November 30, 2010, 04:35:41 pm »

2) os.Path.dirsort() is slow on Windows, this is a known problem, we must have a look.

Filed as bug #19114, we'll try to fix that for next 2.30 Maintenance Release.

Seb
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines