The same in REXX ...

[Autolink] Menu

 
/* ------------------------------------------------------------------ */
/* The same in REXX ...                                               */

  call RxFuncAdd 'SysFileTree', 'REXXUTIL', 'SysFileTree'

  '@ECHO OFF'
  say 'Saving the files *.* into the directory .\backup'

                    /* try to create the directory                    */
                    /* (ignore the return code)                       */
  'md .\backup 2>NUL >NUL'

                    /* try to change to the directory to test if it   */
                    /* exists                                         */
  call directory '.\backup'
  if rc = 0 then
  do
                    /* directory exists, goback into the previous     */
                    /* directory                                      */
    call directory '..'

                    /* get a list of all files (except hidden and     */
                    /* system files)                                  */
    call SysFileTree '*.*', 'files.', 'OF', '*--*-'

                    /* process each file                              */
    do i = 1 to files.0
      curFile = fileSpec( 'N', files.i )

                    /* copy the file                                  */
      'copy ' curFile '.\backup\*.*' '2>NUL >NUL'
      if rc = 0 then
      do
                    /* the copy command was successful                */
                    /* -> delete the file                             */
        'del ' curFile '2>NUL >NUL'

                    /* print a message depending of the result of the */
                    /* del command                                    */
        if rc = 0 then
          say '-W-' curFile 'saved but not deleted.'
        else
          say '---' curFile 'saved and deleted.'
      end /* if rc = 0 then */
      else
                    /* the copy was unsuccessful                      */
        say '-E-' 'Error saving' curFile

    end /* do i = 1 to files.0 */
  end /* if rc = 0 then */
  else
                    /* the directory does not exist                   */
    say '-E- Error accessing the directory .\backup!'


[Back: Using conditional command execution]
[Next: Sample code for parameter parsing]