UDM - forfiles Statement - Breaking Out Using the break Command

forfiles Statement - Breaking Out Using the break Command

The break command is a powerful command that can be issued from inside of a forfiles loop. It causes UDM to stop iterating through the forfiles loop and resume execution at the command immediately following the end statement marking the end of the loop.

One use for the forfiles statement is to try and copy a series of files, deleting the source file if the copy operation was successful.

Example

The following is a sample that accomplishes this task, exiting from the loop if a file cannot be copied or if, after copying a file, it cannot be deleted:

forfiles local=*
   copy local=$(_file)
   if $(_lastrc) NE 0
      print msg="Could not copy $(_path)"
      break
   end
delete local=$(_file)
   if $(_lastrc) NE 0
      print msg="Could not delete $(_path)"
      break
   end
end