Move File - Try Catch and Delete

Hello - Does anyone know if the below is possible?

I am using ‘Move File’ activity to move a number of files from one folder to another. I am getting an exception that if the file already exists that the file can not be moved.

Can I use a Try Catch to skip the exception (if there are files with the same name in the destination folder) and delete that particular file from the source folder? So basically if the file exists delete that file and try to move the next file.

1 Like

we got two options
in MOVE FILE activity we got OVERRIDE option which will override if that file already exists

but if we dont want to make any changes to the already existing file then
instead of TRY CATCH we can validate whether that file exists in that folder or not with PATH EXISTS activity

that is lets say we have five files in a folder and we want to move those files to another folder
but some files are already existing in folder B
the sequence involved will be like
–use a assign activity like this
arr_filepath = Directory.GetFiles(“yourfolderpath”)
where arr_filepath is a variable of type array of string
–now use a FOR EACH activity and pass the above variable as input and change the type argument as string in the property panel of for each loop
–inside the loop use a PATH EXISTS activity and mention the
"yourfolderB path"+"\"+Path.GetFileName(item.tostring)
this will check whether the FILE ALREADY EXISTS OR not and get the outptu with a variable of type boolean name bool_exists
–now inside the loop use a IF condition like this
bool_exists = True
if true it will go to THEN part where we can leave it empty and if false it will go to ELSE part where we can keep our MOVE FILE ACTIVITY with the path and destination mentioned

Cheers @Bob2


Yes you can do that.

And also one option like Override for Move File activity. If file already existing then it will override it.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.