home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / opus / v4 / arexx / delfileslha.rexx < prev    next >
OS/2 REXX Batch file  |  1977-12-31  |  8KB  |  397 lines

  1. /*rx
  2.  *
  3.  * DelFilesLhA.rexx - Delete selected files from an LhA archive previously
  4.  *                    listed in a DOpus window by ListLha.rexx
  5.  *
  6.  * $VER: DelFilesLhA 40.8 (23/05/94) by Geoff Seeley
  7.  *
  8.  * Usage: ARexx command DelFilesLhA.rexx (from DOpus)
  9.  *
  10.  */
  11.  
  12. /* configuration variables (change these to suit your setup) */
  13.  
  14. LhaCommand   = 'XFH_Work:C/Archivers/File/LhA '
  15. OutputWindow = '>CON:30/145/640/100/LhA_Output/CLOSE/SCREENDOPUS.1 '
  16. DeleteList   = 'T:lha_file_list'
  17. ListLhARexx  = 'RX DOpus:ARexx/ListLhA.rexx'
  18.  
  19. /*--------------------------------------------------------------------------*/
  20.  
  21. /* misc. variables */
  22.  
  23. DOpusPort = 'DOPUS.1'
  24.  
  25. LhaDeleteCmd = '-x -m d '
  26.  
  27. if ~show(l,"rexxsupport.library") then        
  28.     call addlib("rexxsupport.library",0,-30,0)
  29.  
  30. /* make sure we've got somebody to talk to */
  31.  
  32. if showlist('Ports', DOpusPort) = 0 then do
  33.    say 'Directory Opus ARexx port not found. Aborting.'
  34.    call CleanUp
  35. end
  36.  
  37. address 'DOPUS.1'
  38. options results
  39.  
  40. TopText "Delete Files From an LhA Archive Buffer"
  41.  
  42. Busy on
  43.  
  44. /* get the path/name of the LhA archive file */
  45.  
  46. 'Status 14 -1'
  47. LhaArchive = result
  48.  
  49. /* make sure it's an LhA archive listing buffer */
  50.  
  51. if (IsLhAFile(LhaArchive) = 0) then do
  52.  
  53.    /* try other window */
  54.  
  55.    OtherWindow
  56.    'Status 14 -1'
  57.    LhaArchive = Result
  58.  
  59.    if (IsLhAFile(LhaArchive) = 0) then do
  60.  
  61.       /* try first selected file */
  62.  
  63.       OtherWindow
  64.       'GetNextSelected -1'
  65.       LhaArchive = RESULT
  66.       if LhaArchive ~= 0 & IsLhaFile(LhaArchive) then do
  67.          call SetRequester
  68.          Request "Delete selected LhA archive?"
  69.          DoDelete = RESULT
  70.          Busy on
  71.          call ReSetRequester
  72.          if DoDelete = "1" then do
  73.             'Status 13 -1'
  74.             LhaPath = RESULT
  75.             LhaArchive = LhaPath || LhaArchive
  76.             call DelLhArchive
  77.             call CleanUp
  78.          end
  79.       end
  80.       else do
  81.          Notify "Sorry, no LhA archive buffer found.\You must use the ListLha button first."
  82.          call CleanUp
  83.       end
  84.    end
  85.  
  86. end
  87.  
  88. /* get path to archive */
  89.  
  90. call FindLhaPath
  91. LhaArchive = LhaPath || LhaArchive
  92.  
  93. /* check for existance of archive */
  94.  
  95. if ~exists(LhaArchive) then do
  96.  
  97.    Notify "Can't seem to find '" || LhaArchive || "'\Aborting."
  98.    call CleanUp
  99.  
  100. end
  101.  
  102. /* check if LhA archive is empty */
  103.  
  104. call GetFileCount
  105.  
  106. if NumFiles = 0 then do
  107.  
  108.    call AskDelArchive
  109.    call CleanUP
  110.  
  111. end
  112.  
  113. /* get list of selected entries */
  114.  
  115. GetSelectedAll
  116. SelectedEntries = result
  117.  
  118. if SelectedEntries = 'RESULT' then do
  119.  
  120.    /* no files selected, delete all? */
  121.  
  122.    call SetRequester
  123.    Request "Delete *ALL* files in LhA archive?"
  124.    DoDelete = RESULT
  125.    Busy on
  126.    call ReSetRequester
  127.  
  128.    if DoDelete = "1" then do
  129.  
  130.       call SetRequester
  131.       Request "Delete LhA archive as well?"
  132.       DelArchive = RESULT
  133.       Busy on
  134.       call ReSetRequester
  135.  
  136.       if DelArchive = "1" then do
  137.          call DelLhArchive
  138.          call CleanUp
  139.       end
  140.       else do
  141.  
  142.          TopText "Deleting File(s) From LhA Archive... Please Wait."
  143.  
  144.          CliCommand = LhaCommand||OutputWindow||LhaDeleteCmd||'"'||LhaArchive||'"'
  145.          CliCommand = CliCommand || ' "*"'
  146.  
  147.          address command CliCommand
  148.  
  149.          NoAskDelete = 1
  150.          call ReListArchive
  151.          call CleanUp
  152.       end
  153.    end
  154.    else do
  155.       TopText "Deletion Of File(s) Aborted..."
  156.       call CleanUp
  157.    end
  158. end
  159.  
  160. NumberOfEntries = words(SelectedEntries)
  161.  
  162. /* make sure user wants it */
  163.  
  164. call SetRequester
  165. Request "Are You *SURE* You Want to DELETE the Selected File(s)?"
  166. DoDelete = Result
  167. call ReSetRequester
  168.  
  169. Busy on
  170.  
  171. if DoDelete = "1" then do
  172.  
  173.    /* delete the files */
  174.  
  175.    call DeleteFileList
  176.    call ReListArchive
  177. end
  178. else do
  179.  
  180.    TopText "Deletion Of File(s) Aborted..."
  181.    call CleanUp
  182.  
  183. end
  184.  
  185. TopText "Finished Deleting Selected File(s) From LhA Archive."
  186. call CleanUp
  187.  
  188. exit
  189.  
  190. /*---------------------------------------------------------------------------*/
  191.  
  192. DeleteFileList: /* build a list of selected files, delete list */
  193.  
  194.    /* toast possible old list */
  195.  
  196.    if exists(DeleteList) then
  197.       delete(DeleteList)
  198.  
  199.    if ~open(FileList, DeleteList, 'W') then do
  200.       Notify "Can't open file " || DeleteList
  201.       call CleanUp
  202.    end
  203.  
  204.    TopText "Creating File(s) List... Please Wait."
  205.  
  206.    do EntryNumber = 1 to NumberOfEntries
  207.       Index = word(SelectedEntries, EntryNumber)
  208.       GetEntry Index + 1
  209.       Entry = result
  210.       File = substr(Entry, 10)
  211.       File = '"' || File || '"'
  212.       call ReplaceMetaChars
  213.       if right(File, 2) ~= '/"' then
  214.          writeln(FileList, File)
  215.       else
  216.          call AskDelDir(File)
  217.       selection = Index ||' '|| 0 ||' '|| 0
  218.       SelectEntry selection
  219.    end
  220.  
  221.    'DisplayDir -1'
  222.  
  223.    close(FileList)
  224.  
  225.    /* form CLI command and delete the file(s) */
  226.  
  227.    TopText "Deleting File(s) From LhA Archive... Please Wait."
  228.  
  229.    CliCommand = LhaCommand||OutputWindow||LhaDeleteCmd||'"'||LhaArchive||'"'
  230.    CliCommand = CliCommand || ' @' || DeleteList
  231.  
  232.    address command CliCommand
  233.  
  234. return
  235.  
  236. /*---------------------------------------------------------------------------*/
  237.  
  238. ReplaceMetaChars: /* replace special wildcards with ? */
  239.  
  240.    File = translate(File, '???', '()`', '?')
  241.  
  242. return
  243.  
  244. /*---------------------------------------------------------------------------*/
  245.  
  246. IsLhAFile: procedure   /* look at extension, return 1 if right, else 0 */
  247.  
  248.    parse arg AFileName
  249.  
  250.    lps = lastpos(".", AFileName)               
  251.    if lps = 0 then                           
  252.       return 0
  253.  
  254.    FileExt = upper(right(AFileName,length(AFileName)-lps))
  255.  
  256.    if FileExt ~= "LHA" & FileExt ~= "LZH" then
  257.       return 0
  258.    else
  259.       return 1
  260.  
  261. return 0
  262.  
  263. /*---------------------------------------------------------------------------*/
  264.  
  265. FindLhAPath: /* grab invisible file path to archive */
  266.  
  267.    /* find number of entries, path is the last one */
  268.  
  269.    'Status 6 -1'
  270.  
  271.    GetEntry Result
  272.    LhaPath = Result
  273.  
  274. return
  275.  
  276. /*---------------------------------------------------------------------------*/
  277.  
  278. GetFileCount: /* get the number of files in the LhA archive */
  279.  
  280.    /* number of files is the second to last line */
  281.  
  282.    'Status 6 -1'
  283.    Idx = Result - 1
  284.    GetEntry Idx
  285.    NumFiles = word(Result, 2)
  286.  
  287. return
  288.  
  289. /*---------------------------------------------------------------------------*/
  290.  
  291. AskDelDir: /* confirm directory deletion */
  292.  
  293.    call SetRequester
  294.    Request "Delete directory "||File||" (and all files within)?"
  295.    DelDir = RESULT
  296.    call ReSetRequester
  297.    Busy on
  298.  
  299.    if DelDir = 1 then do
  300.       File = StripQuotes(File)
  301.       File = '"'||File||'*"'
  302.       writeln(FileList, File)
  303.    end
  304.  
  305. return
  306.  
  307. /*---------------------------------------------------------------------------*/
  308.  
  309. AskDelArchive: /* ask user if they wish to delete the archive */
  310.  
  311.    call SetRequester
  312.    Request "This LhA archive is now EMPTY. Do you want to DELETE it?"
  313.    DeleteArchive = Result
  314.    call ReSetRequester
  315.    Busy on
  316.  
  317.    if DeleteArchive = 1 then
  318.       call DelLhArchive
  319.  
  320. return
  321.  
  322. /*--------------------------------------------------------------------------*/
  323.  
  324. DelLhArchive: /* delete LhA archive and rescan the window */
  325.  
  326.   if exists(LhaArchive) then
  327.      delete(LhaArchive)
  328.  
  329.   /* buffer is toast, so clear it and scan in directory */
  330.  
  331.   'ClearWin -1'
  332.   'ScanDir "'||LhaPath||'"'
  333.  
  334.   TopText "LhA archive deleted."
  335.  
  336. return
  337.  
  338. /*--------------------------------------------------------------------------*/
  339.  
  340. ReListArchive: /* relist the LhA archive after a delete */
  341.  
  342.    address command ListLhARexx
  343.  
  344.    Busy on
  345.  
  346.    /* get number of files left in archive */
  347.  
  348.    call GetFileCount
  349.  
  350.    if NumFiles = 0 & NoAskDelete = 0 then
  351.       call AskDelArchive
  352.  
  353. return
  354.  
  355. /*--------------------------------------------------------------------------*/
  356.  
  357. SetRequester: /* set requester strings */
  358.  
  359.    Status 26
  360.    OldOkay = RESULT
  361.    Status 26 set 'Delete'
  362.    Status 27
  363.    OldCancel = RESULT
  364.    Status 27 set 'Cancel'
  365.  
  366. return
  367.  
  368. /*--------------------------------------------------------------------------*/
  369.  
  370. ReSetRequester: /* reset requester strings */
  371.  
  372.    Status 26 set OldOkay
  373.    Status 27 set OldCancel
  374.  
  375. return
  376.  
  377. /*---------------------------------------------------------------------------*/
  378.  
  379. StripQuotes: procedure
  380.  
  381.    parse arg AFileName
  382.  
  383. return strip(AFileName,, '"')
  384.  
  385. /*---------------------------------------------------------------------------*/
  386.  
  387. CleanUp: /* clean up files and exit */
  388.  
  389.    if exists(DeleteList) then
  390.       delete(DeleteList)
  391.  
  392.    Busy off
  393.    exit
  394.  
  395. return
  396.  
  397.