home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / REXMENU2.ZIP / ATTRMENU.CMD next >
OS/2 REXX Batch file  |  1992-10-27  |  3KB  |  94 lines

  1. /* AttrMenu.cmd - Rexx script to interactively Set or Clear a file attribute
  2.  * in a particular directory.
  3.  * This script is prvided as an example for using RexxMenu.
  4.  */
  5.  
  6. AttrPos = "A*HRS"  /* SysFileTree will use this for mask positions */
  7.  
  8. /* Parse the arguments, and try to be flexible about the order */
  9. ARG Arg1 Arg2 Arg3
  10. if \(Arg3 = "") then signal InvalidInput
  11. if Arg2 = "" then do
  12.    FASpec = "*"
  13.    AttrArg = Arg1
  14. end  /* Do */
  15. else do
  16.    FASpec = Arg1
  17.    AttrArg = Arg2
  18. end  /* Do */
  19.  
  20. if \(LENGTH(AttrArg) = 2) then signal InvalidInput
  21. NewSetting = SUBSTR(AttrArg,1,1)
  22. if NewSetting = '+' then OldSetting = '-'
  23. else OldSetting = '+'
  24. if POS(NewSetting,"+-") = 0 then signal InvalidInput
  25. FAAttr = SUBSTR(AttrArg,2,1)
  26. if POS(FAAttr,AttrPos) = 0 | FAAttr = '*' then signal InvalidInput
  27.  
  28. OldAttrMask = INSERT(OldSetting,'',POS(FAAttr,AttrPos)-1,LENGTH(AttrPos)-(POS(FAAttr,AttrPos)-1),'*')
  29. NewAttrMask = INSERT(NewSetting,'',POS(FAAttr,AttrPos)-1,LENGTH(AttrPos)-(POS(FAAttr,AttrPos)-1),'*')
  30.  
  31. /* ADD RexxMenu function support from the RexxMenu.dll */
  32. if 1 = RxFuncQuery('RexxMenu') then
  33.    CALL RxFuncAdd 'RexxMenu', 'RexxMenu', 'RexxMenu'
  34. /* Also uses SysFileTree to read directory */
  35. CALL RxFuncAdd 'SysFileTree', 'rexxutil', 'SysFileTree'
  36.  
  37. /* Read in directory and act on that directory as long as there are files that
  38.  * match the attribute and as long as user doesn't press escape
  39.  */
  40. FileName = '' /* no initial choice */
  41. do until FileList.0 = 0 | FileName = ''
  42.    call SysFileTree FASpec, 'FileList' , 'OF', OldAttrMask
  43.    if \(FileList.0 = 0) then do
  44.  
  45.       DirPathSpec = INSERT(FILESPEC('drive',FileList.1),FILESPEC('path',FileList.1))
  46.  
  47.       /* build temporary file list to choose from */
  48.       '@if exist AtMnLst.Tmp del AtMnLst.Tmp'
  49.       i = 0
  50.       do while i < FileList.0
  51.          i = i + 1
  52.          '@echo' FileList.i '>> AtMnLst.Tmp'
  53.          '@echo' 'Full Name =' FileList.i '>> AtMnLst.Tmp'
  54.       end /* do */
  55.  
  56.       /* Use RexxMenu for user to choose a file */
  57.       FileName = RexxMenu('AtMnLst.Tmp','/Pre',DirPathSpec,'/Sort','/Esc',,
  58.                           '/Init',FileName,'/Com','Full Name = ',,
  59.                           '/Prompt','SET' AttrArg 'ATTRIBUTE (Esc for none)')
  60.       '@del AtMnLst.Tmp'
  61.  
  62.       if \(FileName = '') then do
  63.          /* alter attribute */
  64.          '@attrib' INSERT(INSERT('"',INSERT(DirPathSpec,FileName)),'"'),
  65.                    INSERT(NewSetting,FAAttr)
  66.       end  /* Do */
  67.    end  /* Do */
  68.    else do
  69.       say 'No More files with the' INSERT(OldSetting,FAAttr) 'attribute.'
  70.    end  /* Do */
  71.  
  72. end /* do */
  73. DROP FileList.
  74.  
  75. EXIT
  76.  
  77.  
  78. InvalidInput:
  79. say ""
  80. say "Use the AttrMenu command to interactively display or change a file attribute."
  81. say
  82. say "SYNTAX:  AttrMenu [drive:][path][filename] <+|-><R|A|S|H>"
  83. say "Where:"
  84. say "  [drive:][path][filename]"
  85. say "                  Specifies the file you want to change."
  86. say "  +               Sets an attribute."
  87. say "  -               Cancels an attribute."
  88. say "  R               Sets the read-only attribute."
  89. say "  A               Sets the archive file attribute."
  90. say "  S               Sets the system file attribute."
  91. say "  H               Sets the hidden file attribute."
  92.  
  93. EXIT
  94.