Char said:
Gotcha. Thanks. Still, it's embarrassingly complex for such a simple
task.
Imagine what it would look like in assembler.
There are other ways to do it. But, the reason I wouldn't
bother posting them, is it would mean downloading a load of
little utility programs to make it happen. (The utilities
would be Windows ports of Linux/Unix programs.) I wanted
something monolithic Metz could use.
However, since this is a "contest", let's try the following.
All done in Windows. (Although I normally do this in Linux,
because all aspects of the command work properly, and the
thing isn't quite as clunky as this happens to run. The ports
barely hang together at times. I have to select my options
with care, on the Windows versions, to get them to run.)
*******
This one line, lists an entire tree and sorts it.
find C:\Downloads -type f -exec ls -al -1 {} ; | sort -t: -k3 > output44.txt
Programs used:
find.exe (
http://gnuwin32.sourceforge.net/packages/findutils.htm)
ls.exe (
http://gnuwin32.sourceforge.net/packages/coreutils.htm)
sort.exe (
http://gnuwin32.sourceforge.net/packages/coreutils.htm)
How the command works:
Find, finds all files meeting the search criterion.
Setting -type f, means match on files and not directories. That
is to prevent directories from being listed. We only want a
file list here, a complete path for each one, so they can be
sorted.
The -exec, means to launch a separate program to handle the path
that find locates. The separate program is "listdir", a.k.a. "ls.exe".
ls -al is to get an output format, to list a fair amount of info about
a file, including the size field.
Much of the garbage emitted, doesn't make sense in a Windows environment
and it's more like noise here.
The {} ; as opposed to {} +, is to call "ls.exe" for each output.
While the {} + option is more economical, testing of the Windows port
with that option, led to a failure. So I had to back off to the less
efficient {} ; syntax.
The sort.exe command comes up next. The pipe symbol "|", pipes the output of
all the forked "ls.exe" commands, to the sort program.
The sort program is told to use ":" as a field separator. Let's take a line
of input to be sorted, to figure out why.
This is the output format, from each time that the "ls.exe" program runs.
White space can't be used as a field delimiter, because file names
can contain spaces. Since I know I'm listing "C:\" , I know I'll have
a colon character I can count on. By making the field separator
the colon character, that splits the line into three pieces. Everything
to the right of the C: colon, is "field 3" of the input line, and is the
thing we wish to sort on.
< ---------------- field #1 ----------------> #2 <---------------------- field #3 ---------------------------->
| |
| |
-rw-rw-rw- 1 User Name 0 32787 2009-10-30 06:29 C:\Downloads/VLC Media Player/vlc-1.0.3/plugins/liba52_plugin.dll
So when I do "sort -t: -k3", that chops the line in three pieces, at
the ":", then does a sort using field 3, in default sort order
(whatever that is). I could add other sort options, if need be.
The stuff on the left, is bogus, and is done by the authors of the
port to keep things consistent with Linux. (The "User Name" field, is my
Windows login name.) What we'd really want to keep, would be something like this.
I have ways I could fix this, on the same line, but doing so would
only obscure things.
Size <--- Date -----> <--------------------------- Name ------------------------------>
32787 2009-10-30 06:29 C:\Downloads/VLC Media Player/vlc-1.0.3/plugins/liba52_plugin.dll
Anyway, I don't think there's any point to dumping the entire listing. For
this example, it was around 4MB or so. The method is slow, because
each file encountered, needs "ls.exe" to run. The sort command, is
pretty fast (fraction of a second), so it contributes little to the
waiting time.
If it was desired to sort on the "size" field, that can be done too. Just
a matter of changing back to white space as a field separator, and
specifying -k 6.
Paul