Move files from one folder to another


#1

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”.


The problem is that in 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 :slight_smile:


#2

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.


#3

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 :slight_smile:


#4

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.


#5

You can check the “Overwrite” property in the Move File activity.

Or if you don’t want to do that, then I recommend utilizing the Retry Scope with a counter.

Retry Scope
    Assign counter = counter + 1    
    Move File // with filename use something like this:
        If(counter=1, filepath, filepath.Replace(".txt",counter.ToString+".txt") )
    

So something like that.


#6

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.


#7

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") )

Thank you so much for your precious help,
Camilla :slight_smile:


#8

Yes, correct.
I would like not to overwrite the files.
They contain different content.
Can you please help me once more?
Thank you so much,
Camilla :slight_smile:


#9

Please see attached a working example.
PathExists_example_TB.xaml (11.5 KB)

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.


#10

my suggestion is give some delay after one file move. or check the file name with Path Exist


#11

Hi.

Here is an example of where I was going with that:

RenameFileRetry.xaml (8.1 KB)

–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.

Regards.


#12

Thank you so much @Bolletje.
I ’ ll try and let you know as soon as possible.
Camilla :blush::blush:


#13

Thank you so much @ClaytonM.
I’ll try and let you know as soon as possible.
Thank you for the helpful response.
Camilla


#14

Thank you so much @ClaytonM.
I tried your solution for my case and it worked.
Camilla.


#15

Thank you so much @Bolletje.
I tried your solution and it works correctly for my problem.
Thank you so much.
Camilla.