web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / search filenames in Sh...
Power Automate
Unanswered

search filenames in Sharepoint library for special character and replace it

(0) ShareShare
ReportReport
Posted on by 10

Hi, we have a big document library and found out that some files have a # in the filename. 

The # is meanwhile forbidden. 

 

Is there a way to create a flow that searches the all filenames in the library and replaces # with _ ?

 

Thanks

Categories:
I have the same question (0)
  • MarvinBangert Profile Picture
    1,924 Most Valuable Professional on at

    Hey @StefT 

    please try the following action and settings to get all items from your SharePoint library that has a '#' in the Filename:

    MarvinBangert_0-1636628940600.png

    substringof('#',FileLeafRef)

    If you would use the Name column, you would see an error, because eventhough the column exists, you cannot use it within the filter. The "FileLeafRef" will give you the 'filename.documenttype', this column we can also filter. Using the substring we checking if there is a '#' within the filename.

     

    Next you would need to run through every item using an "apply to each" and update the FileLeafRef using HTTP:

    MarvinBangert_2-1636629837249.png

    Site Address: <YourSiteAddress>
    Method: POST
    URI: _api/web/lists/getbytitle('Documents')/items(@{items('Apply_to_each')?['ID']})
    Headers:
     Accept: Application/json;odata=verbose
     Content-Type: Application/json;odata=verbose
     IF-MATCH: *
     X-HTTP-Method: MERGE
    Body:
    {'__metadata':{'type':'SP.Data.<Your Library Internal name (Check URL)>Item'},'FileLeafRef':'@{replace(items('Apply_to_each')?['{FilenameWithExtension}'],'#','_')}'}

    The replace expression looks like this:

    replace(items('Apply_to_each')?['{FilenameWithExtension}'],'#','_')

     

    Afterwards your Filenames should have been changed.

     

    Does this help you? Otherwise please give me some more information.

    Best regards
    Marvin

    If you like this post, give a Thumbs up. If it solved your request, Mark it as a Solution to enable other users to find it.

    Blog: Cloudkumpel

  • StefT Profile Picture
    10 on at

    Hi, sorry for my late answer. 

     

    It is not working

     

    The first run returned this error:

     

    The execution of template action 'Apply_to_each' failed: the result of the evaluation of 'foreach' expression 'v@{outputs('Get_files_(properties_only)')?['body/value']}' is of type 'String'. The result must be a valid array.

     

    I tried again and the flow ran successfully. But it took only 12 ms. And no file has been changed on Sharepoint. I uploaded a testfile with some # in the filename. 

     

    StefT_0-1637140730479.png

    I think I copied your flow exactly. 

     

    Any ideas?

    Thank you very much

  • Verified answer
    MarvinBangert Profile Picture
    1,924 Most Valuable Professional on at

    Hey @StefT 

    please check the area within your flow that I marked orange in mine:

    MarvinBangert_0-1637182573256.png

    In the screenshot I can see the placeholder from my post. Please update this area with the URL you can find when you open the library. Maybe could also be "Shared_x0020_Documents" if you use the default library from the site.

     

    Does this help you? Otherwise please give me some more information.

    Best regards
    Marvin

    If you like this post, give a Thumbs up. If it solved your request, Mark it as a Solution to enable other users to find it.

    Blog: Cloudkumpel

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard