Four Js Development Tools Forum

Discussions by product => Genero BDL => Topic started by: David Heydon on November 22, 2010, 01:34:36 PM

Title: os.path.dirsort() rather slow...?
Post by: David Heydon 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 (genero) Select

FUNCTION showDir(path)


    DEFINE path STRING
    DEFINE child STRING
    DEFINE handle INTEGER

    IF NOT os.Path.exists(path) THEN
       RETURN
    END IF
    DISPLAY "[", path, "]"
    DISPLAY "1 ",CURRENT
    CALL os.Path.dirfmask(1+2+4)
    DISPLAY "2 ",CURRENT
    CALL os.Path.dirsort("size",1)
    LET handle = os.Path.diropen(path)
    DISPLAY "3 ",CURRENT
    WHILE handle > 0
       LET child = os.Path.dirnext(handle)
       IF child IS NULL THEN EXIT WHILE END IF
       DISPLAY os.Path.join(path,child)
    END WHILE
    CALL os.Path.dirclose(handle)

END FUNCTION


Title: Re: os.path.dirsort() rather slow...?
Post by: Sebastien FLAESCH 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
Title: Re: os.path.dirsort() rather slow...?
Post by: David Heydon 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

Title: Re: os.path.dirsort() rather slow...?
Post by: Sebastien FLAESCH on November 25, 2010, 10:50:43 AM
Quote from: David Heydon on November 24, 2010, 01:35:00 PM

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
Title: Re: os.path.dirsort() rather slow...?
Post by: David Heydon 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...
Title: Re: os.path.dirsort() rather slow...?
Post by: Sebastien FLAESCH on November 30, 2010, 04:35:41 PM
Quote from: Sebastien FLAESCH on November 23, 2010, 03:02:04 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