home *** CD-ROM | disk | FTP | other *** search
- /* AttrMenu.cmd - Rexx script to interactively Set or Clear a file attribute
- * in a particular directory.
- * This script is prvided as an example for using RexxMenu.
- */
-
- AttrPos = "A*HRS" /* SysFileTree will use this for mask positions */
-
- /* Parse the arguments, and try to be flexible about the order */
- ARG Arg1 Arg2 Arg3
- if \(Arg3 = "") then signal InvalidInput
- if Arg2 = "" then do
- FASpec = "*"
- AttrArg = Arg1
- end /* Do */
- else do
- FASpec = Arg1
- AttrArg = Arg2
- end /* Do */
-
- if \(LENGTH(AttrArg) = 2) then signal InvalidInput
- NewSetting = SUBSTR(AttrArg,1,1)
- if NewSetting = '+' then OldSetting = '-'
- else OldSetting = '+'
- if POS(NewSetting,"+-") = 0 then signal InvalidInput
- FAAttr = SUBSTR(AttrArg,2,1)
- if POS(FAAttr,AttrPos) = 0 | FAAttr = '*' then signal InvalidInput
-
- OldAttrMask = INSERT(OldSetting,'',POS(FAAttr,AttrPos)-1,LENGTH(AttrPos)-(POS(FAAttr,AttrPos)-1),'*')
- NewAttrMask = INSERT(NewSetting,'',POS(FAAttr,AttrPos)-1,LENGTH(AttrPos)-(POS(FAAttr,AttrPos)-1),'*')
-
- /* ADD RexxMenu function support from the RexxMenu.dll */
- if 1 = RxFuncQuery('RexxMenu') then
- CALL RxFuncAdd 'RexxMenu', 'RexxMenu', 'RexxMenu'
- /* Also uses SysFileTree to read directory */
- CALL RxFuncAdd 'SysFileTree', 'rexxutil', 'SysFileTree'
-
- /* Read in directory and act on that directory as long as there are files that
- * match the attribute and as long as user doesn't press escape
- */
- FileName = '' /* no initial choice */
- do until FileList.0 = 0 | FileName = ''
- call SysFileTree FASpec, 'FileList' , 'OF', OldAttrMask
- if \(FileList.0 = 0) then do
-
- DirPathSpec = INSERT(FILESPEC('drive',FileList.1),FILESPEC('path',FileList.1))
-
- /* build temporary file list to choose from */
- '@if exist AtMnLst.Tmp del AtMnLst.Tmp'
- i = 0
- do while i < FileList.0
- i = i + 1
- '@echo' FileList.i '>> AtMnLst.Tmp'
- '@echo' 'Full Name =' FileList.i '>> AtMnLst.Tmp'
- end /* do */
-
- /* Use RexxMenu for user to choose a file */
- FileName = RexxMenu('AtMnLst.Tmp','/Pre',DirPathSpec,'/Sort','/Esc',,
- '/Init',FileName,'/Com','Full Name = ',,
- '/Prompt','SET' AttrArg 'ATTRIBUTE (Esc for none)')
- '@del AtMnLst.Tmp'
-
- if \(FileName = '') then do
- /* alter attribute */
- '@attrib' INSERT(INSERT('"',INSERT(DirPathSpec,FileName)),'"'),
- INSERT(NewSetting,FAAttr)
- end /* Do */
- end /* Do */
- else do
- say 'No More files with the' INSERT(OldSetting,FAAttr) 'attribute.'
- end /* Do */
-
- end /* do */
- DROP FileList.
-
- EXIT
-
-
- InvalidInput:
- say ""
- say "Use the AttrMenu command to interactively display or change a file attribute."
- say
- say "SYNTAX: AttrMenu [drive:][path][filename] <+|-><R|A|S|H>"
- say "Where:"
- say " [drive:][path][filename]"
- say " Specifies the file you want to change."
- say " + Sets an attribute."
- say " - Cancels an attribute."
- say " R Sets the read-only attribute."
- say " A Sets the archive file attribute."
- say " S Sets the system file attribute."
- say " H Sets the hidden file attribute."
-
- EXIT