Is there a better option than DIR or LS for listing files?

Microsoft Windows
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Contact:

Is there a better option than DIR or LS for listing files?

Post by MigrationUser »

20 Feb 2021 04:23
Rekrul

Many years ago, on the Amiga, I recall having a Dir/LS command that had a staggering number of options. You could format the output in pretty much any way you could think of.

I've tried all the options in Dir and I've even downloaded a couple different ports of the Unix LS command, but none of them will do exactly what I want.

Ideally, I'd like it to recursively list all the files in all the sub-directories with the size in bytes listed first, followed by the relative path and filename. Like this;

Code: Select all

    49,152  Test1\Stuff.txt
     4,096  Test2\Junk.txt
12,121,369  Videos\Demo.mp4
However I can't find a program that will list the relative path name in front of the filename. They all list the directories separately, then list the files that are in them.

Using;

Code: Select all

for /r %%F in (*.*) do echo %%~zF %%F
Prints the sizes without commas and not neatly aligned, plus it prints the full path including the drive letter, which I do not want.

With either method, I'm going to have to jump through a ton of hoops to try and reformat the list the way I want it. It would be so much easier if there was a third-party Dir command that let you format the output how you wanted.

Does such a thing exist?

----------------------------

#2 21 Feb 2021 11:06
T3RRY


the dir command has options for sorting and grouping output, and when iterated over from within a for /f loop you can strip the drive letter by just using the ~p modifier.

/A: is the atrribute Switch,subswitch '-D' denotes NOT directory
/S is the recursive switch of the Dir command
/O: is the switch for Sort order, S is the subswitch to sort by size (smallest first), G is the subswitch to group directories while sorting.

From the command line:

Code: Select all

@(For /F "Delims=" %G in ('dir /B /S /A:-D /O:SG')Do @Echo(%~zG %~pG) | @more
~p will effectively only strip 'DriveLetter:' from the path, if you wish to remove path elements up to and including the location of the parent folder from the path string, you'll need to assign the path to a variable and use substring modification to remove the unwanted parts of the path from the string.
Post Reply