I have one problem in moving a file from a folder to an another one.
I should move the file from the folder “D:\Disdette_Outlook\ricevute” to the folder “D:\Disdette_Outlook\indice_storico”.
there exists already a file with the same name so I cannot move the file from one folder to the other one because it gives me this message: Move file : Cannot create a file when that file already exists.
How it is possible to handle with the problem of files with the same name?
Is it possible to rename the file ibefore moving it to another folder so that there is no problem of overwriting?
Thank you so much,
First check whether a file with the same name already exists. You can use the Path Exists activity for this. This will give you a boolean.
If a file with the same name does not exists, then you can use the Move File or Copy File activity.
If a file with the same name does exists, then you can change the file name and add a suffix to it, like a number.
Think of using Do While ; if Path Exists is True then incrementally increase the suffix number, as it can happen that a file with a suffix was also already there. Do this until Path Exists is False.
Overwrite can be used as well (simple check box property in Move File activity), but then you lose the old files.
Depends on what you want. Looking at the file names in the screenshot, it looks like a data extract from a system. It could be the case that there will be multiple extracts with the same name, but with different content.
Thank you so much.
Can I ask you if you can share a simple workflow with the activity? Retry Scope Assign counter = counter + 1 Move File // with filename use something like this: If(counter=1, filepath, filepath.Replace(“.txt”,counter.ToString+“.txt”) )
–Increments suffix counter
–Assigns output file path using the counter if it’s not = to 1
----using input filepath to get filename or replace that variable with the file used in a For each, and combine with the output directory folder.
–Move file, and if it fails a retry attempt occurs.