home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / sosutl11.zip / filefind.cmd < prev    next >
OS/2 REXX Batch file  |  1993-08-21  |  5KB  |  162 lines

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