Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

DIR output is backwards, any way to change it?

Dec
47
2
The default output of DIR is:

Untitled-2.jpg

Just my opinion but this is completely backwards. The normal reading order is left to right. File names should be first, not last.

Is there any (easy) way to change this?
 
Here's one way of doing it, using PDIR and the FFIELDS command from the TextUtils plugin;
Code:
r:\>pdir /(f %@char[9] dy/m/d %@char[9] th:m:s %@char[9] zc) |! ffields
temp                   2022/04/22  13:34:29  <DIR>
01-amanwithaneed.mp3   2022/03/10  09:42:06  16,045,708
02-amaninthenight.mp3  2022/03/10  09:42:14  18,118,222
03-awomanatawell.mp3   2022/03/10  09:42:21  17,970,748
04-amaninthetombs.mp3  2022/03/10  09:42:27  19,380,782
05-amanupatree.mp3     2022/03/10  09:42:32  14,036,216
06-awomanwithajar.mp3  2022/03/10  09:42:37  14,939,150
odbc.exe               2014/09/30  14:16:29  33,792
results.htm            2022/04/17  13:31:11  15,500
screen.dat             2022/04/22  07:36:52  4,872
TRNSCTNS.DBF           2022/04/21  14:27:58  146,404
ws.dsn                 2022/04/21  14:28:10  255
zlb.txt                2022/04/17  13:43:27  5,918
...or as an alias...
Code:
r:\>alias myway=`pdir /(f %@char[9] dy/m/d %@char[9] th:m:s %@char[9] zc) |! ffields`

r:\>myway
temp                   2022/04/22  13:38:55  <DIR>
01-amanwithaneed.mp3   2022/03/10  09:42:06  16,045,708
02-amaninthenight.mp3  2022/03/10  09:42:14  18,118,222
03-awomanatawell.mp3   2022/03/10  09:42:21  17,970,748
04-amaninthetombs.mp3  2022/03/10  09:42:27  19,380,782
05-amanupatree.mp3     2022/03/10  09:42:32  14,036,216
06-awomanwithajar.mp3  2022/03/10  09:42:37  14,939,150
odbc.exe               2014/09/30  14:16:29  33,792
pdir                   2022/04/22  13:38:42  0
results.htm            2022/04/17  13:31:11  15,500
screen.dat             2022/04/22  07:36:52  4,872
TRNSCTNS.DBF           2022/04/21  14:27:58  146,404
ws.dsn                 2022/04/21  14:28:10  255
zlb.txt                2022/04/17  13:43:27  5,918

PDIR allows one to customize as desired.

Joe
 
DIR /Z also puts filenames on the left. The catch is, you only get the first eleven characters....
 
Here's one way of doing it, using PDIR and the FFIELDS command from the TextUtils plugin;
Code:
r:\>pdir /(f %@char[9] dy/m/d %@char[9] th:m:s %@char[9] zc) |! ffields
Well, PDIR does indeed work, and I can get the display output that I want ... sort of ... BUT ... only in very limited and very specific circumstances.

PDIR really only works, IF:
(1) All the filenames in a directory are more or less the same length
(2) Or, if there are longer filenames they are only at the top of the directory listing
(3) File names don't contain spaces

(Note that Joe's example matches #2 and #3.)

Otherwise, the output of PDIR (with or without | FFIELDS) is pretty much a mess.

It appears that I have accidentally discovered the real reason why TCC and CMD display directory contents backwards, with the filename last instead of first. Because the length of filenames can vary greatly, making it is extremely difficult to put the filename first and then get everything else (size, date, etc. ) to line up in nice neat columns. Maybe not impossible, but way too complicated.

Oh well, it was a learning experience. Thanks to everyone.
 
If you want to be ambitious, you can write a BTM file that caches the file information in one or more arrays in memory, keeping track of the maximum filename width as you go, and then generates the output lined up accordingly.

15-20 years ago, I would have probably written it and posted it here.

With age, comes wisdom. I leave the actual implementation to the reader. :cool:
 
File names displayed last because
1. Filename length is an unknown factor.
2. Filename itself is an unknown factor.
If you would start your listing from filename, its content could potentially be confused with other data in the list. If you have filenames of varying length, you would either have the rest of the columns' content in random places across the screen, or if you align the next column by the maximum filename length, it may as well ride off-screen. Linux standard 'ls' tool also list file names last in the long formats. Do you think it is a coincidence?
 
I just tripped over this again and realized I made it sound harder than it actually is.
Have the BTM file iterate over all the filenames (wildcard expanded) from the command line.
Keep the longest width, then build a PDIR command string in a variable and execute it via @EXEC[] or @EXECSTR[].

Extra credit if you add some logic to prevent any line from wrapping or spilling off the right, plus a user-defined function to do a fairly smart elision of an input so you can still tell which file is which even if some are elided on output.

If this runs too slowly for you, there's always the option of coding it in 'C'... :joyful:
 
Here's a first (possibly last) attempt at shortening a string and inserting an ellipsis in the middle. Strings with funky characters (notably, space) have to be quoted and the quotes stay. It doesn't handle strings shorter than the desired length. Below, l = the desired length, s = the string, x = length of the left part, y = length of the right part.

1660072300424.png


It would probably be easier, and work better, in a plugin.
 

Similar threads

Back
Top