home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / FFRX.ZIP / FINDFILE / FINDFILE.CMD next >
OS/2 REXX Batch file  |  1992-06-24  |  5KB  |  136 lines

  1. /* FINDFILE.CMD - REXX to find requested file by mask */
  2. /* ================================================================== */
  3. /* Syntax:  see syntax at end of program.                             */
  4. /* Function:  given a filespec mask, optional drive list, FINDFILE    */
  5. /* uses REXX SysFileTree to construct a list of file names matching   */
  6. /* the given filespec mask (which has usual DOS wild cards).  The     */
  7. /* output is then passed to the OS/2 Editor for access, or the user   */
  8. /* can request browse of the output using the BROWSE keyword.         */
  9. /* ================================================================== */
  10. /* This program is written in REXX for OS/2 2.0 You can make this a   */
  11. /* desktop program object by "create another" program object and      */
  12. /* specifying "PMREXX.EXE" as the program name and the name of this   */
  13. /* REXX file:  FINDFILE.CMD as the parameter, giving the full path    */
  14. /* name:  C:\$CMD\FINDFILE.CMD   for example.  This program is in the */
  15. /* Public Domain.  Written by Bruce E. Hogman, Sr. Systems Engineer,  */
  16. /* EDS Corp., for US DOE/EIA, Washington DC, 1992.                    */
  17. /*                                                                    */
  18. /*            ┌─────────────────────────────────────────┐             */
  19. /*            │ Author:  Bruce E. Högman  BIX:  bhogman │             */
  20. /*            │ NaSpa:  HogmBru3  CompuServ: 72050,1327 │             */
  21. /*            └─────────────────────────────────────────┘             */
  22. /*                                                                    */
  23. /* ================================================================== */
  24. '@echo off'
  25. /* Load RexxUtils at startup */
  26. call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  27. call SysLoadFuncs
  28. environ=address()
  29. do forever
  30. say ' '
  31. dphrase=""
  32. say 'Enter search values -or- null reply to END -or- ? for help'
  33. parse pull filespec drvstr opts
  34. cwd=directory()
  35. if '\'\=substr(cwd,length(cwd),1) then cwd=cwd||'\'
  36. editfile=cwd||'FINDFILE.TXT'
  37. if filespec="" then exit
  38. if filespec="?" then do
  39.    call syntax; iterate;
  40. end;
  41. browse=0
  42. browse=pos("BRO",TRANSLATE(opts))
  43. if browse>0 then do
  44.    editfile=""
  45. end
  46. rmt= pos("RE",TRANSLATE(opts)) | pos("RM",TRANSLATE(opts))
  47. rmtstr="LOCAL"
  48. rphrase="(LOCAL drives only)"
  49. if rmt>0 then do
  50.    rmtstr="USED"
  51.    rphrase="(REMOTE drives also)"
  52. end
  53. if browse<1 then do
  54.    irc=SysFileDelete(editfile)
  55.    isc=stream(editfile,'c','open write')
  56.    if isc\='READY:' then do
  57.       utxt="Can't open" editfile "for output.  Continue in BROWSE mode?"
  58.       utitl="Error opening output file."
  59.       if environ='PMREXX' then do
  60.          uact=RxMessageBox(utxt,utitl,'OKCANCEL','ERROR')
  61.       end
  62.       else do
  63.          say utitl utxt
  64.          parse pull rply
  65.          if 'Y'=translate(substr(rply,1,1)) then uact=1
  66.          else uact=2
  67.       end
  68.       if uact>1 then exit
  69.       editfile=""
  70.       browse=1
  71.    end
  72. end
  73. if drvstr = '*' | drvstr="" then do
  74.    drvmap=SysDriveMap('A:',rmtstr)
  75.    dphrase="ALL by default"
  76. end
  77. else do
  78.    dphrase="as specified"
  79.    drvmap=""
  80.    do i=1 to length(drvstr);
  81.       drvmap=drvmap||substr(drvstr,i,1)||": "
  82.    end
  83. end
  84. idrv=1
  85. ioc=LINEOUT(editfile,"Drives to search =" drvmap)
  86. ioc=lineout(editfile,"   " dphrase rphrase)
  87. do while idrv<length(drvmap)
  88.    xdrv=substr(drvmap,idrv,2)
  89.    ifo=""
  90.    ifo=sysdriveinfo(xdrv);
  91.    if ifo\="" then do
  92.       isc=lineout(editfile," ")
  93.       irc=SysFileTree(xdrv||"\"||filespec,fstr,BSO)
  94.       isc=lineout(editfile,"Drive: " xdrv " found" fstr.0 'files using "'||filespec||'"')
  95.       do i=1 to fstr.0
  96.          isc=LINEOUT(editfile,fstr.i)
  97.       end
  98.    end
  99.    else do
  100.       isc=LINEOUT(editfile,"Drive: " xdrv "is NOT READY - bypassed.")
  101.    end
  102.    fstr.0=0
  103.    idrv=idrv+3
  104. end
  105. if browse=0 then do
  106.    isc=stream(editfile,'c','close')
  107.    'e' editfile
  108. end
  109. end /* do forever */
  110. syntax: procedure;
  111.    say ' '
  112.    say 'Syntax of FINDFILE:'
  113.    say ' '
  114.    say 'FINDFILE file_spec_mask [drv_letters] [options]'
  115.    say ' '
  116.    say '   file_spec_mask  like:  f*.exe '
  117.    say ' '
  118.    say 'Optional parameters:'
  119.    say ' '
  120.    say '   drv_letters     like:  cdefgh  or * for all local drives'
  121.    say ' '
  122.    say '   options:  REMOTE       for remote drives - use only with * for drives'
  123.    say '             BROWSE       to browse the output.  Default is to invoke '
  124.    say '                          the OS/2 Editor to view the list.'
  125.    say ' '
  126.    say 'Default operation, if only the file_spec is given, is to search'
  127.    say 'all LOCAL drives, all subdirectories, and display the list of files.'
  128.    say 'Use * for drives to search all local and remote drives.'
  129.    say ' '
  130.    say 'Examples:'
  131.    say ' '
  132.    say '   findfile f*.exe cdef'
  133.    say '   findfile *.inf * remote'
  134.    say '   findfile d:\*.wp '
  135.    RETURN
  136.