[comp.unix.xenix] DOS directory utility

davidsen@steinmetz.steinmetz.UUCP (William E. Davidsen Jr) (09/08/87)

Although I'm not a big fan of MSDOS I often have to move data between
Xenix and DOS. I find myself fighting with the directory utility, and
therefore wrote this utility shell. It creates a listing of all files,
sorted, doesn't get ugly when files are >99k, and does a total.

I assume that everyone used "dosls x:|sort|pr -4t" when needed, this is
just to handle the case when a complete list is needed.

---------------- cut here and set executable ----------------
:
#
#  DOS directory utility for Xenix
#
#  Bill Davidsen - 8/4/87
#
#  reads, sorts, format and analizes a DOS volume

# get the volume name
if [ -n "$1" ]
then
   volname=$1
else
   echo "Device? \c"
   read ans
   volname=$ans
fi

# read, sort, analize
dosdir $volname | sort |
awk '
BEGIN {
   # set name format in display
   #  0 - "NAME     EXT"
   #  1 - "NAME.EXT    "
   format=0
}

{
   # set the values
   name = $1
   if (substr($0,10,1) == " ") {
      ext = ""
      size = $2+0
      dtime = $3 " " $4
   }
   else {
      ext = $2
      size = $3+0
      dtime = $4 " " $5
   }

   s+=size
   if (format == 1)
   {
      fname=name "." ext
      printf("%-12s %7d   %s\n", fname, size, dtime)
   }
   else
   {
      printf("%-8s %-3s %7d   %s\n", name, ext, size, dtime)
   }
}

END {
   printf("\n%20d bytes in %d files\n", s, NR)
}'
---------------- end ----------------
-- 
	bill davidsen		(wedu@ge-crd.arpa)
  {uunet | philabs | seismo}!steinmetz!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me