Operating System - OpenVMS
1827251 Members
2876 Online
109716 Solutions
New Discussion

Re: How to list files by size

 
Stuart Holt
New Member

How to list files by size

Does anyone know how to list the contents of a directory by size order on VMS?
4 REPLIES 4
Ian Miller.
Honored Contributor

Re: How to list files by size

There does not appear to be an option for the DIRECTORY command but you could put the result to a file and use the sort command.
____________________
Purely Personal Opinion
Joseph Huber_1
Honored Contributor

Re: How to list files by size


A commandfile doing directory and sorts it by size was posted on comp.os.vms some years ago,
it does what You want probably: see the attachemnt.
http://www.mpp.mpg.de/~huber
Hein van den Heuvel
Honored Contributor

Re: How to list files by size

Right, a little command file to pipe DIR/SIZE output into SORT is the way to solve thus classic problem under VMS.


If you are familiar with perl, or willing to go there, then you might consider a script like below:

----- tmp.pl ----

$wildcard_spec=shift @ARGV or die "Please provide wildcarded filespec(s)";
while ($wildcard_spec) {
foreach (glob $wildcard_spec) {
$size{$_} = -s;
}
$wildcard_spec=shift @ARGV;
}
foreach (sort {$size{$b} <=> $size{$a}} keys %size) {
printf "%9dKB %s\n", $size{$_}/1024, $_;
}

---- sample usage ----


$ pipe perl tmp.pl *.txt *.obj | perl -ne "print if ($i++ < 10)"
976KB rmsstats_all.txt
58KB etrade.txt
38KB security.txt
32KB s.obj
24KB copy_lbn.obj
24KB a.txt
22KB b.txt
15KB getuai.obj
13KB intercept.txt
10KB test.txt

hth,
Hein.
Håkan Markström
New Member

Re: How to list files by size

Here is a simple pip command for descending order.
Just remove "desc" to change order.

$ pip dir/siz/wid=file=40 | sort/key=(pos:42,siz:8,desc) sys$input sys$output

Regards,
Hakan