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 Automate
Unanswered

Rename File in folder

(0) ShareShare
ReportReport
Posted on by 56

Hello All - I have a requirement to rename the file in the One drive. Every month client send us the file which is suffixed with month and year in below formats,

Ex -

1.  backup_Feb-24.xlsx 

2. Summary_Feb-24.xlsx

3. Invoice-Feb24.xlsx

4. Data_Febrauary-2024.xlsx

 

We receive plenty of files in different format but I have a list of standard naming convention for each file, The above file name consist part of standard naming convention as below

 

1.  backup.xlsx 

2. Summary\.xlsx

3. Invoice.xlsx

4. Data.xlsx

 

What are the possible solutions to achieve this requirement. 

I have the same question (0)
  • Deenuji_Loganathan_ Profile Picture
    6,250 Super User 2025 Season 2 on at

    @mohan2mm 

     

    Here's what you need to do:

    1. Begin by defining all the suffix details in the list.For example: _Feb or -Feb or #Feb or any suffix details in the list.

    2. Then, configure your folder path as indicated below, and apply the necessary file filter.

    3. Finally, you can use the file rename action to remove all suffix details by replacing them with an empty string.

     

     

    Deenuji_1-1709315933505.png

    Deenuji_0-1709315890672.png

    Code:

    SET Suffix_list TO ['_Feb-24', '_Febrauary-2024']
    Folder.GetFiles Folder: $'''C:\\Users\\OneDrive \\Excel File''' FileFilter: $'''*xlsx''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> Files
    LOOP FOREACH Current_File_Path IN Files
    LOOP FOREACH Suffix_item IN Suffix_list
    File.RenameFiles.RenameReplaceText Files: Current_File_Path TextToReplace: Suffix_item IfFileExists: File.IfExists.DoNothing RenamedFiles=> RenamedFiles
    END
    END

     

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

    If I've resolved your query, please consider accepting it as the solution and giving it a thumbs up to help others find answers faster.

     

     

  • SandhiyaDurga Profile Picture
    18 on at

    Hi @mohan2mm 

     

    Please find the below solution,

     

    Step1: Get all files in the Folder.

    Step2: Loop through each file and using Crop text, remove from "_" till "."

    Step3: Rename file with croppedText output value and extension.

     

    SandhiyaDurga_0-1709549520388.png

    SandhiyaDurga_1-1709549541389.png

     

     

    If I've resolved your query, please consider accepting it as the solution and giving it a thumbs up to help others find answers faster.

     

     

    Thank you,
    Sandhiya P
  • mohan2mm Profile Picture
    56 on at

    Hello Deenuji - Thanks for your response.

     

    The file names in the folder are inconsistent Ex - File_Dec-23, File1-Dec-23, File2Dec-23.

     

    So there is no constant character to loop and rename.

     

    However I have the list of file names i.e File, File1 and File2, I there a possibility I do wild search and the closest one I rename with standard name.

  • Deenuji_Loganathan_ Profile Picture
    6,250 Super User 2025 Season 2 on at

    @mohan2mm 

     

    Try if this make sense to you(without any scripting language).

    Begin by listing all your file names in the list variable. Next, we will utilize text parsing to verify whether the file names mentioned in the list exist within the file name. If they do, we will then proceed to rename the file by removing all additional characters and retaining only the file name.

     

    Deenuji_1-1709569656993.png

     

    Code:

    SET File_list TO ['backup', 'Summary', 'Invoice', 'Data']
    Folder.GetFiles Folder: $'''C:\\Users\\OneDrive - office365journey\\Excel File''' FileFilter: $'''*xlsx''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> Files
    LOOP FOREACH Current_File_Path IN Files
    LOOP FOREACH File_item IN File_list
    Text.ParseText.ParseForFirstOccurrence Text: Current_File_Path.Name TextToFind: File_item StartingPosition: 0 IgnoreCase: True OccurrencePosition=> Position
    IF Position = 0 THEN
    File.RenameFiles.Rename Files: Current_File_Path NewName: File_item KeepExtension: True IfFileExists: File.IfExists.DoNothing RenamedFiles=> RenamedFiles
    EXIT LOOP
    END
    END
    END

     

     

    --------------------------------------------------------------------------------------------------------------------------
    If I've resolved your query, please consider accepting it as the solution and giving it a thumbs up to help others find answers faster.

     

     

  • mohan2mm Profile Picture
    56 on at

    @Deenuji 

     

    I tried a couple of ways but no fruitful result.

     

    I have a folder in the desktop called "abc" in this folder there is an excel file by name "Invoice_test", which I want to rename as "Invoice" using Prase Text.

     

    I have attached the screen shot of the flow, please guide me where i have gone wrong. 

     

    Note - I'm trying with one file currently and this is dummy data after getting sucessful result will go with real time requirement.

     

    mohan2mm_0-1710132843673.png

     

     

     

     

  • Deenuji_Loganathan_ Profile Picture
    6,250 Super User 2025 Season 2 on at

    @mohan2mm 
    The below code working fine for me. In case if you facing any issues please share some screenshot of error.

     

     

    SET File_list TO ['Invoice']
    Folder.GetFiles Folder: $'''C:\\Users\\OneDrive\\Demo\\abc''' FileFilter: $'''*xlsx''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> Files
    LOOP FOREACH Current_File_Path IN Files
     LOOP FOREACH File_item IN File_list
     Text.ParseText.ParseForFirstOccurrence Text: Current_File_Path.Name TextToFind: File_item StartingPosition: 0 IgnoreCase: True OccurrencePosition=> Position
     IF Position = 0 THEN
     File.RenameFiles.Rename Files: Current_File_Path NewName: File_item KeepExtension: True IfFileExists: File.IfExists.DoNothing RenamedFiles=> RenamedFiles
     EXIT LOOP
     END
     END
    END

     

     

  • mohan2mm Profile Picture
    56 on at

    @Deenuji - There is no as such error, the Flow is getting executed but the file names is not getting renamed.

     

    Is there a way i can copy your code and paste it into my flow to resolve this issue ?

  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    The reason why you are not getting the expected result is the fact that both of your loops are iterating through the same collection - the list of files. While in the actual recommended scenario, your inner loop should be iterating through the list of keywords, and not files.

     

    And yes, you can copy the code @Deenuji provided and paste it directly into your PAD designer - the actions will be created for you automatically.

  • Deenuji_Loganathan_ Profile Picture
    6,250 Super User 2025 Season 2 on at

    @Agnius Welcome back ❤️💐

     

    @mohan2mm:

    Please check the below image and replace your second loop file with file_list.

    Deenuji_0-1710137402907.png

     

    As @Agnius mentioned, you copy my code like below and paste into you PAD designer.

    Deenuji_1-1710137524532.pngDeenuji_2-1710137628144.png

    Thanks,
    Deenuji Loganathan
    🤖 Automation Evangelist
    Deenuji - Follow me on LinkedIn

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🌟

  • mohan2mm Profile Picture
    56 on at

    This is awesome, it started working and appreciate the explanation.

     

    I have other challenge with few files, where the actual file names are as below

    "Availability Details - Oct 2023_Bronze"

    "Availability Details - Oct 2023_Gold"

     

    want to rename them as 

    "Availability Details_Bronze"

    "Availability Details_Gold"

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 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard