Hello friends,
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,
Camilla
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.
Thank you so much.
I’ll attach my workflow; i cannot manage to let the Rename Method work in the workflow. sposta_file_indice.xaml (14.6 KB)
Can you please have a look?
Thank you so much,
Camilla
You don’t need a custom Rename activity. Simply use the output property of the ‘Move File’; using filename and then adding the suffix. It will then automatically rename it as well.
In many cases the input file name and output file name are the same , but in your case you are dealing with these duplicates.
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”) )
I have included a ‘Copy File’ activity at the end for testing purposes. You can easily replace it with a ‘Move File’ activity with the same properties.
Assign InputPath to your ‘cartella_input’ and OutputPath to your "D:\Disdette_Outlook\indice_storico"
Of course you can complete this process with less variables and less activities, but I have included those for easy understanding.
–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.