cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frequent Visitor

Copy File - If another file is already there - Enter Custom Value

Hello,

 

I'm developing a really simple flow that copy files from one folder to other, but when another file is already in the destination folder I want that the Flow copy the file with a new name. However, the default option just add +1 to the file name. That is a problem because the file's name that I want to copy ends with numbers, so adding +1 change the meaning of the file name.

 

I would like to use a custom new name. Instead of +1 would be nice is it were (+1), but I don't know how to build the expression.

 

For example:

 

Original File in the folder:

"file54673.docx"

 

Duplicate name copied file:

"file54673(1).docx" instead of the default new name value "file546731.docx"

 

And if it were copied several times:

"file54673(2).docx"

"file54673(3).docx"

"file54673(n).docx"

 

I found a similar request but folders instead of files, but apparently that options wasn't available back them:

https://powerusers.microsoft.com/t5/Building-Flows/quot-If-another-folder-is-already-here-quot-custo...

 

Thanks in advance.

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Community Support
Community Support

Hi @DavidRHG ,

 

Yes, as the mentioned link that you provided, your requirement couldn't be achieved with the "Copy file" action since the custom name is not supported in the "Copy file" action.

The easiest way would be use the "Create file" action replace the "Copy file" action. the "Create file" action would allow the custom file name, and you need to check if the file name existed, if don't exists, copy the file, else if existed, create the file with new name.

You could refer to solution below to copy the files from two libraries:

1.png2.png

 

The length expression in the Condition as below:

length(body('Filter_array'))

The concat expression in the Create file action as below:

concat(first(split(triggerBody()?['{FilenameWithExtension}'],'.')),'(',add(length(body('Filter_array')),1),')','.',last(split(triggerBody()?['{FilenameWithExtension}'],'.')))

 

When a file is created in library, and the file is not existed in the library 2, the flow would run successfully as below:

3.png

When a file is created in library1, and the file is existed in the library2, the flow would run successfully as below:

4.png

 

Best regards,

Alice   

Community Support Team _ Alice Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Super User III
Super User III

Hi!

Sharepoint, right? Can you share a screenshot from your current flow design, so we can verify the action block you are currently using?

Anyone, one possible approach is to list files in the destination folder...

Flow_redistributeFilesTeamsSharepoint_3.png

...doublecheck first if there is a file with the same name in the destination folder...

Flow_redistributeFilesTeamsSharepoint_4.png

...if so, there are several methods to 'copy' files:

-'move file', 'copy file': you cannot choose the destination filename

-'create file': you can choose the destination filename, but you need to get file content first

As far as I remember, rename file is not available yet, so the usual workaround is to 'create file'

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



View solution in original post

6 REPLIES 6
Community Support
Community Support

Hi @DavidRHG ,

 

Yes, as the mentioned link that you provided, your requirement couldn't be achieved with the "Copy file" action since the custom name is not supported in the "Copy file" action.

The easiest way would be use the "Create file" action replace the "Copy file" action. the "Create file" action would allow the custom file name, and you need to check if the file name existed, if don't exists, copy the file, else if existed, create the file with new name.

You could refer to solution below to copy the files from two libraries:

1.png2.png

 

The length expression in the Condition as below:

length(body('Filter_array'))

The concat expression in the Create file action as below:

concat(first(split(triggerBody()?['{FilenameWithExtension}'],'.')),'(',add(length(body('Filter_array')),1),')','.',last(split(triggerBody()?['{FilenameWithExtension}'],'.')))

 

When a file is created in library, and the file is not existed in the library 2, the flow would run successfully as below:

3.png

When a file is created in library1, and the file is existed in the library2, the flow would run successfully as below:

4.png

 

Best regards,

Alice   

Community Support Team _ Alice Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Super User III
Super User III

Hi!

Sharepoint, right? Can you share a screenshot from your current flow design, so we can verify the action block you are currently using?

Anyone, one possible approach is to list files in the destination folder...

Flow_redistributeFilesTeamsSharepoint_3.png

...doublecheck first if there is a file with the same name in the destination folder...

Flow_redistributeFilesTeamsSharepoint_4.png

...if so, there are several methods to 'copy' files:

-'move file', 'copy file': you cannot choose the destination filename

-'create file': you can choose the destination filename, but you need to get file content first

As far as I remember, rename file is not available yet, so the usual workaround is to 'create file'

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



View solution in original post

Hello @efialttes ,

 

Yep, SharePoint. Is a variation of the same Flow that you helped me with yesterday.

Is working just fine as far as I tested.

 

2020-04-27 08_28_33-Microsoft Edge.png

 

2020-04-27 08_30_19-Microsoft Edge.png

 

2020-04-27 08_31_13-.png

 

 

My flow, supposedly, copy new files of one folder to a new or existing folder based on a code that is in the files names.

 

Thanks,

 

 
 

 

 

Hello @v-alzhan-msft ,

 

I will try your solution. However, I'm curious about why custom name is not supported in "copy file".

I thought it was possible using an expression in the option highlighted in the image below:

 

2020-04-27 08_31_13-.png

 

thanks

 

 

@v-alzhan-msft 

 

Thank you very much…. It works perfectly.

 

Best regards,

Dear @efialttes,

 

Thank you, this solution also works. Is very similar to the first one. 

 

Best regards,

 

Helpful resources

Announcements
PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Top Solution Authors
Users online (7,253)