home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / sosutl12.zip / bin / filefind.cmd < prev    next >
OS/2 REXX Batch file  |  1993-10-18  |  5KB  |  172 lines

  1. /* --------
  2.  * FileFind (C) SuperOscar Softwares, Tommi Nieminen 1993.
  3.  * --------
  4.  * WhereIs written in REXX.
  5.  *
  6.  * Usage:
  7.  *     [D:\] filefind [PATH\]MASK ... [ /h /n /? ]
  8.  *
  9.  * Switches:
  10.  *     /h      Find hidden and system files too.
  11.  *     /n      Brief format: display fully qualified file names only.
  12.  *     /?      Display help page and quit.
  13.  *
  14.  * 24-Feb-1993  v1.0: first version ready.
  15.  * 26-Feb-1993  v1.0a: bug corrections.
  16.  * 26-Feb-1993  v1.1: multiple file parameters allowed.
  17.  * 4-Jul-1993   v1.2: national date and time formats supported.
  18.  * 12-Aug-1993  v1.3: bug fixes; enhanced switch handling; /n switch.
  19.  * 17-Aug-1993  v1.4: /h switch.
  20.  * 6-Sep-1993   v1.4a: unknown switches cause an error.
  21.  */
  22.  
  23. Parse Arg find "/"switches
  24.  
  25.   /* Program name */
  26. prgname = "FileFind v1.4a"
  27.  
  28.   /* Constants */
  29. TRUE = 1
  30. FALSE = 0
  31.  
  32.   /* Defaults */
  33. hidden_files = FALSE
  34. names_only = FALSE
  35.  
  36.   /* Examine switches */
  37. switches = Translate(switches)
  38. Do i = 1 To Length(switches)
  39.     ch = SubStr(switches, i, 1)
  40.  
  41.     Select
  42.         When ch == "H" Then
  43.             hidden_files = TRUE
  44.  
  45.         When ch == "N" Then
  46.             names_only = TRUE
  47.  
  48.         When ch == "?" Then
  49.             Call Help
  50.  
  51.         Otherwise
  52.             Call Error "unknown switch '/"ch"' (use /? to get help)"
  53.     End
  54. End
  55.  
  56. If find == "" Then Call Error "no parameters (use /? to get help)"
  57.  
  58.   /* Set attribute mask (format "ADHRS", "+" = set, "-" = not set, "*" =
  59.    * ignore
  60.    */
  61. If hidden_files == FALSE Then
  62.     attrib_mask = "*--*-"
  63. Else
  64.     attrib_mask = "*-***"
  65.  
  66.   /* Don't load anything unnecessary when viewing in brief format */
  67. If names_only == FALSE Then Do
  68.       /* Load SysFileTree() and SysIni() functions */
  69.     Call RxFuncAdd "SysFileTree", "RexxUtil", "SysFileTree"
  70.     Call RxFuncAdd "SysIni", "RexxUtil", "SysIni"
  71.  
  72.       /* Read national language settings from "os2.ini" */
  73.     iDate = SysIni("user", "PM_National", "iDate")
  74.     iTime = SysIni("user", "PM_National", "iTime")
  75.     sDate = SysIni("user", "PM_National", "sDate")
  76.     sTime = SysIni("user", "PM_National", "sTime")
  77.  
  78.       /* Bug warning: in certain situations strange results may be
  79.        * returned by SysIni().
  80.        */
  81.     datefmt = Abs(Left(iDate, 1))
  82.     time24 = Abs(Left(iTime, 1))
  83.     datesep = Left(sDate, 1)
  84.     timesep = Left(sTime, 1)
  85. End
  86.  
  87.   /* Go through all parameters */
  88. Do i = 1 To Words(find)
  89.  
  90.       /* Find files */
  91.     ok = SysFileTree(Word(find, i), files, "fst", attrib_mask)
  92.  
  93.       /* Display results in national format */
  94.     Do j = 1 To files.0
  95.  
  96.         If names_only == FALSE Then Do
  97.  
  98.               /* Separate different parts of date-time string */
  99.             datetime = Translate(Word(files.j, 1), " ", "/")
  100.             year = Format(Word(datetime, 1), 2)
  101.             mon = Format(Word(datetime, 2), 2)
  102.             day = Format(Word(datetime, 3), 2)
  103.             hour = Format(Word(datetime, 4), 2)
  104.             min = Word(datetime, 5)
  105.  
  106.             Select
  107.                 When datefmt == 0 Then
  108.                     date = mon || datesep || day || datesep || year
  109.                 When datefmt == 1 Then
  110.                     date = day || datesep || mon || datesep || year
  111.                 When datefmt == 2 Then
  112.                     date = year || datesep || mon || datesep || day
  113.                 Otherwise
  114.                     Call Error "Date format code ==" datefmt"!!??"
  115.             End
  116.  
  117.             Select
  118.                 When time24 == 0 Then Do
  119.                     ampm = "am"
  120.                     If hour > 12 Then Do
  121.                         ampm = "pm"
  122.                         hour = Format(hour - 12, 2)
  123.                     End
  124.                     time = hour || timesep || min || ampm
  125.                 End
  126.                 When time24 == 1 Then
  127.                     time = hour || timesep || min
  128.                 Otherwise
  129.                     Call Error "Time format code ==" timefmt"!!??"
  130.             End
  131.  
  132.               /* Other information */
  133.             size = Format(Word(files.j, 2), 8)
  134.             attr = Word(files.j, 3)
  135.             fname = Word(files.j, 4)
  136.  
  137.               /* Display information */
  138.             Say date time size attr fname
  139.         End /* If !names_only */
  140.  
  141.         Else
  142.             Say Word(files.j, 4)
  143.  
  144.     End /* Do j */
  145.  
  146. End /* Do i */
  147.  
  148. Exit 0
  149.  
  150. Error: Procedure Expose prgname
  151.     Parse Arg msg
  152.  
  153.     Say prgname":" msg
  154. Exit 1
  155.  
  156. Help: Procedure Expose prgname
  157.     Say prgname "(C) SuperOscar Softwares, Tommi Nieminen 1993."
  158.     Say
  159.     Say "    [D:\] filefind [PATH\]MASK ... [ /h /n /? ]"
  160.     Say
  161.     Say "FileFind is a file find program written in REXX. It finds files that"
  162.     Say "match given MASK(s) under given PATH(s). Hidden and system files and"
  163.     Say "directories are NOT found."
  164.     Say
  165.     Say "If PATH is not given, its default value is the current directory."
  166.     Say
  167.     Say "Switches:"
  168.     Say "    /h      find hidden and system files too"
  169.     Say "    /n      brief format: display only full path names"
  170.     Say "    /?      display this help"
  171. Exit 0
  172.