cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Revlock97
Resolver I
Resolver I

Move File with New Name/Version

I have a flow wherein part of it moves a file from Production Version to Previous Version. I set the "If another file is already there" to Move with New Name but the result is just a number added at the end if there is a file of the same name (e.g. File.docx, File1.docx)


I want the increment to be incased in parenthesis to avoid confusion if the file name ends in numbers already (e.g. File.docx, File(1).docx) but I am unable to come up with the right Expression to accomplish this in the "If another file is already there" input.

 

Thank you very much in advance for any help!

Revlock97_0-1668564042126.png

 

 

6 REPLIES 6
v-xiaochen-msft
Community Support
Community Support

Hi @Revlock97 ,

 

I made a sample for you.

vxiaochenmsft_0-1668570184147.png

vxiaochenmsft_1-1668570197118.png

vxiaochenmsft_2-1668570239982.png

_api/web/lists/getbytitle('TestGG')/items(@{outputs('Move_file')?['body/ItemId']})

 

{
  "Content-Type": "application/json",
  "IF-MATCH": "*",
  "X-HTTP-Method": "MERGE"
}

 

{'FileLeafRef':'@{replace(outputs('Move_file')?['body/Name'],'1','(1)')}'}

 

vxiaochenmsft_3-1668570312841.png

 

Best Regards,

Wearsky

Hello @v-xiaochen-msft 

 

So far it has worked as intended but the problem is it only stops at (1) but doesn't increment to (2) , (3) and so on

Revlock97_1-1668572134391.png

 

 

I have tried the follow directly on the "If the file already exists" input

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


from : https://powerusers.microsoft.com/t5/Building-Flows/Copy-File-If-another-file-is-already-there-Enter-...

the output seems to work but it returns with an  error:

"to be converted doesn't have the expected format 'int/int3'"

 

Thanks a lot  for the reply btw

 

v-xiaochen-msft
Community Support
Community Support

Hi @Revlock97 ,

 

I made a sample for you.

vxiaochenmsft_0-1668585187674.png

vxiaochenmsft_1-1668585258047.png

lastIndexOf(outputs('Get_files_(properties_only)')?['body/value']?[0]?['{FilenameWithExtension}'],')')
 
lastIndexOf(outputs('Get_files_(properties_only)')?['body/value']?[0]?['{FilenameWithExtension}'],'(')
 
slice(outputs('Get_files_(properties_only)')?['body/value']?[0]?['{FilenameWithExtension}'],add(lastIndexOf(outputs('Get_files_(properties_only)')?['body/value']?[0]?['{FilenameWithExtension}'],'('),1),lastIndexOf(outputs('Get_files_(properties_only)')?['body/value']?[0]?['{FilenameWithExtension}'],')'))
 
replace(outputs('Get_files_(properties_only)')?['body/value']?[0]?['{Name}'],outputs('Compose_3'),string(add(int(outputs('Compose_3')),1)) )
 
vxiaochenmsft_2-1668585380812.png
vxiaochenmsft_3-1668585394076.png

 

 

Best Regards,

Wearsky

Hello  @v-xiaochen-msft 

 

Sorry I'm still quite new to this. I've followed it exactly but it returns an error in compose 4:

Revlock97_0-1668588185960.png

 

 
v-xiaochen-msft
Community Support
Community Support

Hi @Revlock97 ,

 

I missed something in 'get files' action.

vxiaochenmsft_0-1668588470634.png

startswith(FileLeafRef,'@{concat(slice(split(outputs('Move_file')?['body/Name'],'.')?[0],0,-1),'(')}')

 

Best Regards,

Wearsky

Hello @v-xiaochen-msft ,

 

Really sorry again, after applying the filter it returns the error

Revlock97_1-1668590556535.png

 

 

because the Output in get properties returns NULL. Tried removing it and the Compose 4 error returns again despite the last file in Previous Version after moving is at least "Sample Test File1.docx"

 

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (5,607)