[Info-vax] Suggestion: Adding a /SORT option to DIRECTORY and F$SEARCH ?

Dave Froble davef at tsoft-inc.com
Tue Jan 25 20:08:59 EST 2022


On 1/25/2022 7:21 PM, Arne Vajhøj wrote:
> On 1/25/2022 3:50 PM, Dave Froble wrote:
>> On 1/25/2022 2:09 PM, Simon Clubley wrote:
>>> It would be nice to be able to see the output from a DIRECTORY command
>>> optionally sorted by one of largest size, smallest size, oldest date,
>>> newest date, etc.
>>>
>>> Likewise, it would be nice to be able to optionally specify the sort
>>> order in which filenames are returned by f$search().
>>>
>>> Does anyone agree ?
>>
>> Already wrote it, in Basic.  Want a copy?
>
> Python code:
>
> from os import listdir, stat
> from sys import argv, exit
> from time import strftime, localtime
>
> if len(argv) < 4:
>     print('Usage: python dir.py <dir> <orderby> <order>')
>     exit(1)
> sel = lambda f : f[0]
> if argv[2].lower() == 'name':
>     sel = lambda f : f[0]
> if argv[2].lower() == 'size':
>     sel = lambda f : f[1].st_size
> if argv[2].lower() == 'time':
>     sel = lambda f : f[1].st_mtime
> rev = False
> if argv[3].lower() == 'asc':
>     rev = False
> if argv[3].lower() == 'desc':
>     rev = True
>
> allf = [(f,stat(f)) for f in listdir(argv[1])]
> allf.sort(reverse=rev, key=sel)
> for f in allf:
>     print('%-32s %10d %s' % (f[0], f[1].st_size, strftime('%d-%b-%Y %H:%M:%S',
> localtime(f[1].st_mtime))))
>
> Arne
>

It was much more fun, and educational, writing it in Basic ...

-- 
David Froble                       Tel: 724-529-0450
Dave Froble Enterprises, Inc.      E-Mail: davef at tsoft-inc.com
DFE Ultralights, Inc.
170 Grimplin Road
Vanderbilt, PA  15486


More information about the Info-vax mailing list