cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Roguefox77
New Member

Renaming Folders - the name is a date format and need to change to a different format

Hi all,

 

I have a list of folders that are named in a date format of "1 April 2012" and I would like to rename them in a different format as "2012_04_01"

 

Have looked around the forums and most seem to be relating to renaming files. Can anyone help me?

 

Thanks

8 REPLIES 8
grantjenkins
Community Champion
Community Champion

Are you trying to rename all folders within a library/folder? And if so, do you have sub folders that also need to be renamed as part of the same renaming process?



----------------------------------------------------------------------

If I've answered your question, please mark the post as Solved.

If you like my response, please consider giving it a Thumbs Up.
grantjenkins
Community Champion
Community Champion

Assuming they are just top-level folders, here's a solution that might get what you're after.

 

In this example, I've got three folders within the To Be Renamed folder that we will rename with the date formatted as yyyy-MM-dd.

 

grantjenkins_1-1669530075096.png

 

Below is the full flow. I'll go into each of the actions.

grantjenkins_5-1669530486901.png

 

List folder will give us a list of the top-level folders within the To Be Renamed folder. Note that this will not return any sub folders.

grantjenkins_2-1669530142649.png

 

Apply to each will take in the body of List folder and iterate over each of the folders.

grantjenkins_3-1669530184927.png

 

Folder Name is a Compose action that converts the date into a proper date, then formats it as yyyy-MM-dd. The expression used is below. Note that we could have formatted the output directly in parseDateTime but then we would need to add a locale which I wanted to avoid here.

formatDateTime(parseDateTime(items('Apply_to_each')?['Name']), 'yyyy-MM-dd')

grantjenkins_4-1669530466730.png

 

Lastly, we use a Send an HTTP request to SharePoint to rename the folder with the new formatted name.

grantjenkins_6-1669530554650.png

 

The Uri is below. The reason I use slice here is to remove the preceding / from the path.

_api/web/GetFolderByServerRelativeUrl('@{slice(item()?['Path'], 1)}')/ListItemAllFields

 

The Body is below. It takes the output from Folder Name.

{
  "Title": "@{outputs('Folder_Name')}",
  "FileLeafRef": "@{outputs('Folder_Name')}"
}

 

After running the flow, we should get the following result.

 

grantjenkins_7-1669530763190.png



----------------------------------------------------------------------

If I've answered your question, please mark the post as Solved.

If you like my response, please consider giving it a Thumbs Up.

Grant, thanks for this. The only issue is that there is a requirement for a sharepoint site relating to the "List Folder" step and I don't have that. Is there any way in which similar steps can be done without the need for a sharepoint site?

 

Sorry to be a pain with this- I follow all the other steps perfectly well.

 

Thank you

Roguefox77
New Member

If it is any further help- these are folders in my PICTURES library and are available on OneDrive. 

Roguefox77_0-1669534103651.png

 

You can use the SharePoint connector List folder for your OneDrive folders too. You will just need to paste in the URL of your OneDrive. Then you should be able to navigate to your My files which is called Documents.

 

grantjenkins_0-1669534650910.png

 

You'll also need to change the Send an HTTP request to SharePoint Site Address to point to your OneDrive.

 

grantjenkins_1-1669535041903.png

 

 

Note: You can use any of the SharePoint connectors for OneDrive since OneDrive is effectively a SharePoint site behind the scenes.



----------------------------------------------------------------------

If I've answered your question, please mark the post as Solved.

If you like my response, please consider giving it a Thumbs Up.
Roguefox77
New Member

Grant,

 

No, when I try the List Folder step and connect to Sharepoint, i don't even get that far. I get an "Unable to retrieve tenant info" error that pops up. I would assume the List Folder step would be available for OneDrive but can't see it.

 

Any thoughts?

 

Roguefox77_0-1669535775658.png

 

Can you click on Sign in and sign in with your username and password? It might automatically sign you in since you're already connected to your OneDrive.

 

If you can't then it might be that your account is limited to just OneDrive.

 

Unfortunately, OneDrive is lacking in folder operations via Power Automate.



----------------------------------------------------------------------

If I've answered your question, please mark the post as Solved.

If you like my response, please consider giving it a Thumbs Up.
Roguefox77
New Member

Yes, there is no option for sign in with username and password- seems I am stuck with OneDrive. Do I need a sharepoint site to do this, and is it worth having anyway?

 

I really appreciate your feedback and responses. 🙂

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!

Top Solution Authors
Top Kudoed Authors
Users online (4,439)