home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / os2 / sosutl10.zip / FINDFILE.CMD next >
OS/2 REXX Batch file  |  1993-07-05  |  4KB  |  123 lines

  1. /* ------------
  2.  * findfile.cmd (C) Tommi Nieminen 1993.
  3.  * ------------
  4.  * WhereIs written in REXX.
  5.  *
  6.  * 24.02.1993   v1.0: first version ready.
  7.  * 26.02.1993   v1.0a: bug corrections.
  8.  * 26.02.1993   v1.1: multiple file parameters allowed.
  9.  * 04.07.1993   v1.2: national date and time formats supported.
  10.  */
  11.  
  12. Parse Arg find
  13.  
  14. prgname = "findfile.cmd v1.2"
  15.  
  16. If find == "" Then Call Error "no parameters (use /? to get help)"
  17. If find == "/?" Then Call Help
  18.  
  19.   /* Load SysFileTree() and SysIni() functions */
  20. Call RxFuncAdd "SysFileTree", "RexxUtil", "SysFileTree"
  21. Call RxFuncAdd "SysIni", "RexxUtil", "SysFileTree"
  22.  
  23.   /* Read national language settings from "os2.ini" */
  24. iDate = SysIni("user", "PM_National", "iDate")
  25. iTime = SysIni("user", "PM_National", "iTime")
  26. sDate = SysIni("user", "PM_National", "sDate")
  27. sTime = SysIni("user", "PM_National", "sTime")
  28.  
  29.   /* SysIni() return strings seem to cause a lot of trouble: when I tried
  30.    * to call all these functions together like
  31.    *    datefmt = Abs(Left(SysIni( ...
  32.    * REXX always disliked the syntax. There are also strange extra char-
  33.    * acters in the Ini entries -- eg. sDate and sTime contain (in my own
  34.    * os2.ini) a space character after the actual separator. That's why
  35.    * Left() and Abs() functions must be called.
  36.    *
  37.    * Bug warning: in certain situations strange results may be returned
  38.    * by SysIni(): I once got '0' as the date and time separators when I
  39.    * ran Windows programs in a window.
  40.    */
  41. datefmt = Abs(Left(iDate, 1))
  42. time24 = Abs(Left(iTime, 1))
  43. datesep = Left(sDate, 1)
  44. timesep = Left(sTime, 1)
  45.  
  46.   /* Go through all parameters */
  47. Do i = 1 To Words(find)
  48.  
  49.       /* Find files. Files with D(irectory), H(idden) and (S)ystem attribute
  50.        * are discarded. Attribute string (the last SysFileTree() parameter)
  51.        * is of the format "ADHRS"; "*" means don't care, "-" attribute not
  52.        * set, "+" attribute is set.
  53.        */
  54.     ok = SysFileTree(Word(find, i), files, "fst", "*--*-")
  55.  
  56.       /* Display results in national format */
  57.     Do j = 1 To files.0
  58.  
  59.           /* Separate different parts of date-time string */
  60.         datetime = Translate(Word(files.j, 1), " ", "/")
  61.         year = Format(Word(datetime, 1), 2)
  62.         mon = Format(Word(datetime, 2), 2)
  63.         day = Format(Word(datetime, 3), 2)
  64.         hour = Format(Word(datetime, 4), 2)
  65.         min = Word(datetime, 5)
  66.  
  67.         Select
  68.             When datefmt == 0 Then
  69.                 date = mon || datesep || day || datesep || year
  70.             When datefmt == 1 Then
  71.                 date = day || datesep || mon || datesep || year
  72.             When datefmt == 2 Then
  73.                 date = year || datesep || mon || datesep || day
  74.             Otherwise
  75.                 Call Error "Date format code ==" datefmt"!!??"
  76.         End
  77.  
  78.         Select
  79.             When time24 == 0 Then Do
  80.                 ampm = "am"
  81.                 If hour > 12 Then Do
  82.                     ampm = "pm"
  83.                     hour = Format(hour - 12, 2)
  84.                 End
  85.                 time = hour || timesep || min || ampm
  86.             End
  87.             When time24 == 1 Then
  88.                 time = hour || timesep || min
  89.             Otherwise
  90.                 Call Error "Time format code ==" timefmt"!!??"
  91.         End
  92.  
  93.           /* Other information */
  94.         size = Format(Word(files.j, 2), 8)
  95.         attr = Word(files.j, 3)
  96.         fname = Word(files.j, 4)
  97.  
  98.           /* Display information */
  99.         Say date time size attr fname
  100.     End
  101. End
  102.  
  103. Exit 0
  104.  
  105. Error: Procedure Expose prgname
  106.     Parse Arg msg
  107.  
  108.     Say prgname":" msg
  109. Exit 1
  110.  
  111. Help: Procedure Expose prgname
  112.     Say prgname" (C) SuperOscar Softwares, Tommi Nieminen 1993."
  113.     Say
  114.     Say "findfile.cmd is a file find program written in REXX. It finds files"
  115.     Say "matching given mask(s) under a given path.  Hidden and system files"
  116.     Say "and directories are not found."
  117.     Say
  118.     Say "   Usage: [D:\] whereis { [PATH\]FILE ... | /? }"
  119.     Say
  120.     Say "If PATH is not given, its default value is '.' (the current direct-"
  121.     Say "ory)."
  122. Exit 0
  123.