home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR24 / DSIZE10.ZIP / DIRSIZE.CMD next >
OS/2 REXX Batch file  |  1993-02-23  |  5KB  |  130 lines

  1. /*****************************************************************************/
  2. /* Directory Size Survey                                                     */
  3. /* (c) Paul Gallagher 1993                                                   */
  4. /*****************************************************************************/
  5.  
  6. '@echo off'
  7. versionStr='v1.0'
  8. Say "DirSize" versionStr "(c) Paul Gallagher 1993 {paulg@a1.resmel.bhp.com.au}"
  9. Say
  10.  
  11. /*---------------------------------------------------------------------------*/
  12. /* Load REXXUTIL                                                             */
  13. /*---------------------------------------------------------------------------*/
  14. If RxFuncQuery('SysLoadFuncs') <> 0 Then
  15.   If RxFuncAdd('SysLoadFuncs','RexxUtil','SysLoadFuncs') <>0 Then Do
  16.     Say 'Unable to init REXX Utility function loader.'
  17.     Exit
  18.   End
  19. Call SysLoadFuncs
  20.  
  21. /*---------------------------------------------------------------------------*/
  22. /* Set error traps                                                           */
  23. /*---------------------------------------------------------------------------*/
  24. signal on failure name ExitProc
  25. signal on halt name ExitProc
  26. signal on syntax name ExitProc
  27.  
  28. /*---------------------------------------------------------------------------*/
  29. /* Do initial parse of command line and call help message if required        */
  30. /*---------------------------------------------------------------------------*/
  31. /* get the command line arguments */
  32. Parse Arg params
  33. /* call help routine if required */
  34. If Pos(Translate(params),"/?/HELP") > 0 Then Do
  35.   Call HelpInfo
  36.   Signal ExitProc
  37. End
  38.  
  39. /* see if /d [list in order of size] used */
  40. If Pos('/D',Translate(params)) > 0 Then Do
  41.   sort=1
  42.   params=Delstr(params,pos('/D',Translate(params)),2)
  43. End
  44. Else sort=0
  45.  
  46. /* see if /mXXXXX [mask by size] used */
  47. Parse Value Translate(params) With guff'/M'minsize
  48. masksize=Datatype(minsize,'N')
  49. If Pos('/M',Translate(params)) > 0 Then
  50.   params=Delstr(params,pos('/M',Translate(params)))
  51.  
  52. /*---------------------------------------------------------------------------*/
  53. /* Start user procedure                                                      */
  54. /*---------------------------------------------------------------------------*/
  55.  
  56. 'dir 'params'/s|RXQUEUE'
  57. 'echo **QENDS**|RXQUEUE'
  58.  
  59. If (sort) Then Do
  60.   temp1=SysTempFileName('dirsize.I??','?')
  61.   If temp1='' Then Call ErrorMsg 'Failed file operation'
  62.   temp2=SysTempFileName('dirsize.O??','?')
  63.   If temp2='' Then Call ErrorMsg 'Failed file operation'
  64. End
  65.  
  66. data=''
  67. dir='*ns*'
  68. totalsize=0
  69. totalshown=0
  70. Do While (first\='**QENDS**')
  71.   Parse Pull first second data dummy.1
  72.   If first='Directory' Then dir=data
  73.   If (second='file(s)') & (dir\='*ns*') Then Do
  74.     If (sort) Then Call LineOut temp1,Format(data,12)'    'dir
  75.     Else If \(masksize & (data<minsize)) Then Do
  76.       Say dir'    'data 'bytes'
  77.       totalshown=totalshown+data
  78.     End
  79.     totalsize=totalsize+data
  80.     dir='*ns*'
  81.   End
  82. End
  83.  
  84. If (sort) Then Do
  85.   Call LineOut temp1
  86.   'type 'temp1' | sort/r > 'temp2
  87.   Do While Lines(temp2)>0
  88.     Parse Value Strip(LineIn(temp2),'L') With data' 'dir
  89.     If \(masksize & (data<minsize)) Then Do
  90.       Say Strip(dir,'L')'    'data 'bytes'
  91.       totalshown=totalshown+data
  92.     End
  93.   End
  94.   Call LineOut temp2
  95.   If SysFileTree(temp1, 'file', 'F') > 0 Then Call ErrorMsg 'Not enough memory'
  96.   Else If file.0>0 Then 'del' temp1
  97.   If SysFileTree(temp2, 'file', 'F') > 0 Then Call ErrorMsg 'Not enough memory'
  98.   Else If file.0>0 Then 'del' temp2
  99. End
  100.  
  101. Say
  102. If (masksize) Then
  103.   Say 'Size of listed directories:' totalshown 'bytes'
  104. Say 'Size of directory tree:' totalsize 'bytes'
  105.  
  106. /*---------------------------------------------------------------------------*/
  107. /* General exit procedure                                                    */
  108. /*---------------------------------------------------------------------------*/
  109. ExitProc:
  110.   Drop temp1 temp2 sort totalsize
  111.   Drop dummy. first second data
  112.   Drop params versionStr
  113. Exit
  114. /*****************************************************************************/
  115. /* end of main routine                                                       */
  116. /*****************************************************************************/
  117.  
  118. /*****************************************************************************/
  119. /* routine to display help message                                           */
  120. /*****************************************************************************/
  121. HelpInfo: Procedure
  122.   Say " Summarises disk usage on a directory by directory basis"
  123.   Say " Usage:"
  124.   Say "        DirSize [filespec] [dir options] [/D] [/Mxxx]"
  125.   Say " Where:"
  126.   Say "        filespec and dir options are as per DIR command"
  127.   Say "        /D - list directories in descending order of size"
  128.   Say "        /Mxxx - only display directories with size > xxx bytes"
  129.   Say
  130. Return