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:
Thanks in advance.
Solved! Go to Solution.
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:
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:
When a file is created in library1, and the file is existed in the library2, the flow would run successfully as below:
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.
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...
...doublecheck first if there is a file with the same name in the destination folder...
...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
Proud to be a Flownaut!
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:
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:
When a file is created in library1, and the file is existed in the library2, the flow would run successfully as below:
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.
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...
...doublecheck first if there is a file with the same name in the destination folder...
...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
Proud to be a Flownaut!
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.
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:
thanks
Dear @efialttes,
Thank you, this solution also works. Is very similar to the first one.
Best regards,
User | Count |
---|---|
89 | |
37 | |
26 | |
13 | |
12 |
User | Count |
---|---|
128 | |
53 | |
38 | |
26 | |
21 |