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
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?
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.
Below is the full flow. I'll go into each of the actions.
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.
Apply to each will take in the body of List folder and iterate over each of the folders.
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')
Lastly, we use a Send an HTTP request to SharePoint to rename the folder with the new formatted name.
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.
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
If it is any further help- these are folders in my PICTURES library and are available on OneDrive.
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.
You'll also need to change the Send an HTTP request to SharePoint Site Address to point to your OneDrive.
Note: You can use any of the SharePoint connectors for OneDrive since OneDrive is effectively a SharePoint site behind the scenes.
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?
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.
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. 🙂
User | Count |
---|---|
94 | |
39 | |
24 | |
22 | |
16 |
User | Count |
---|---|
128 | |
49 | |
48 | |
32 | |
24 |