Copy Files - want task to finish even with error - VisualCron - Forum

Community forum

hjohnson
2019-05-06T15:47:01Z
Hello,

I have a task of copying files. I want to have the errors still show up in the error output, but I want the task to continue and finish out. Example: we had one file that had a permissions issue, which then failed the whole task and stopped the job. I would like the task to report that permissions issue but then continue on instead of stopping. It is a one task that I am running, so there is no continuing onto another task.

I have thought about unchecking permission denied in the On Error tab, but am not sure if it would report the "error" in the error output.

Thank you,

Heather
Gary_W
2019-05-09T19:54:13Z
Are you looping through a list or doing a copy with a wildcard?
hjohnson
2019-05-09T20:04:39Z
We are copying with a wild card. We are basically copying all of our production files to our dev server, in order to have updated information on the dev server.
Support
2019-05-10T12:08:49Z
In the Flow tab of that Task you can set On Error->Continue.
Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Gary_W
2019-05-10T14:33:15Z
But that's continue with the next task, not continue with the current task of copying files, after logging the file that caused the error. I suspect a powershell or .net script is going to be needed for this.
thomas
2019-05-10T16:33:20Z
I guess you know this, but Robocopy can do all of this including the logging of failed files in one line of code
Gary_W
2019-05-10T18:45:09Z
Thanks Thomas, robocopy is powerful and I admit I forgot all about it. In the meantime I came up with this. I tested by copying one of the files to the destination folder and making it readonly. It worked as expected. $source is passed in as a job variable. I am not a powershell expert so I'm sure some improving could be done. Anyway, food for thought.


#  Start

#
# Copy .txt files from the source folder to the dest folder.
# Logs to $source\test.log
#
Param(
  [Parameter(Mandatory=$true)]
  [string] $source
)

$files = $source + "\*.txt" 
$dest  = $source + "\test"
$log   = $source + "\test.log"

# build a litst of the files to copy
get-childitem -Path $files | foreach {
  try {
    copy $_.fullname $dest -errorAction stop

    # If control makes it here then the copy was successful
    echo "$_ copied OK to $dest" | out-file -append $log
  }
  catch {
    # if the copy failed, log why
    $ErrorMessage = $Error[0].Exception.Message
    echo "ERROR - $_" | out-file -append $log
  }
  # Try to copy the next file
}

#  end
Support
2019-05-11T10:58:26Z
Originally Posted by: Gary_W 

Thanks Thomas, robocopy is powerful and I admit I forgot all about it. In the meantime I came up with this. I tested by copying one of the files to the destination folder and making it readonly. It worked as expected. $source is passed in as a job variable. I am not a powershell expert so I'm sure some improving could be done. Anyway, food for thought.


#  Start

#
# Copy .txt files from the source folder to the dest folder.
# Logs to $source\test.log
#
Param(
  [Parameter(Mandatory=$true)]
  [string] $source
)

$files = $source + "\*.txt" 
$dest  = $source + "\test"
$log   = $source + "\test.log"

# build a litst of the files to copy
get-childitem -Path $files | foreach {
  try {
    copy $_.fullname $dest -errorAction stop

    # If control makes it here then the copy was successful
    echo "$_ copied OK to $dest" | out-file -append $log
  }
  catch {
    # if the copy failed, log why
    $ErrorMessage = $Error[0].Exception.Message
    echo "ERROR - $_" | out-file -append $log
  }
  # Try to copy the next file
}

#  end



Hi Gary, this might be interesting to add in the new Task repository so it can be easily used by other users. Have you looked at the Task repository?

Henrik
Support
http://www.visualcron.com 
Please like  VisualCron on facebook!
Gary_W
2019-05-13T12:52:49Z
Not yet, as we are not on that version. When we get there I will have some code to contribute and look forward to other's tips and tricks also!
Scroll to Top