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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Building a Flow in Pow...
Power Automate
Suggested Answer

Building a Flow in Power Automate Desktop

(0) ShareShare
ReportReport
Posted on by 4


Hi everyone,

I’m trying to build a Power Automate Desktop (PAD) flow that does the following:

 

  1.  

    Monitor a root folder including all subfolders. New files are occasionally added in those subfolders.


  2.  

    Select only files whose names contain:

     

    •  

      a term in square brackets [ ... ], and


    •  

      a term in round parentheses ( ... ).



    •  

  3.  

    Copy those files to a staging folder.


  4.  

    In the staging folder, rename each file by removing the round parentheses and everything inside them (leave the square-bracketed part intact).


  5.  

    Copy the renamed file to a final destination folder.



  6.  
 

Example

Input filename: Report Q3 [ClientA] (v2 draft).pdf

Desired renamed filename: Report Q3 [ClientA].pdf (no extra spaces before the extension)

 

Questions

 

  •  

    What’s the cleanest PAD pattern to:

    a) recurse through subfolders,

    b) filter only files that have both [ ... ] and ( ... ) in their names, and

    c) safely rename without leaving double spaces?


  •  

    Are there recommended PAD actions/ordering to avoid file-lock or path issues?



  •  
 

Regex I’m considering

 

  •  

    To check that a filename has both square brackets and parentheses (for an If condition):

    \[[^\]]+\].*\([^)]+\)


  •  

    To remove the parentheses (and their content) during rename (Replace Text with regex):

    \s*\([^)]*\) → replace with nothing


  •  

    Optional cleanup to collapse double spaces after removal:

    \s{2,} → single space


  •  

    Optional: trim spaces before the extension (if needed), e.g., replace \s+\. with .



  •  
 

If anyone has a concise PAD recipe (actions order, examples, or screenshots) for this pattern, I’d really appreciate it. Thanks!

Categories:
I have the same question (0)
  • Suggested answer
    Nived_Nambiar Profile Picture
    18,138 Super User 2026 Season 1 on at
     
    Try this PAD script 
     
    SET FolderPath TO $'''%''%'''
    Folder.GetFiles Folder: FolderPath FileFilter: $'''*[*]*;*(*)*''' IncludeSubfolders: True FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> Files
    LOOP FOREACH CurrentItem IN Files
        Text.Replace Text: CurrentItem.NameWithoutExtension TextToFind: $'''\\s*\\(.*\\)\\s*''' IsRegEx: True IgnoreCase: False ReplaceWith: $'''%''%''' ActivateEscapeSequences: False Result=> NewFileName
        File.RenameFiles.Rename Files: CurrentItem NewName: NewFileName KeepExtension: True IfFileExists: File.IfExists.Overwrite
    END
    
     
    See whether this helps !
     
     

    Thanks & Regards,
    Nived N

    Stay connected:
    LinkedIn | YouTube | Blogs

    Was this answer helpful?
    If yes, please mark it as the solution by selecting the checkbox in the discussion thread.
    Your feedback motivates me to keep contributing. Thank you!

  • JG-29031445-0 Profile Picture
    4 on at

     

    Nived, Thank you very much for your reply. Is there a simple way to just paste the script you wrote, or do I need to build it step by step?

     

     

  • Suggested answer
    Nived_Nambiar Profile Picture
    18,138 Super User 2026 Season 1 on at
     
    You can copy paste the script to designer panel in PAD - 
     

    Thanks & Regards,
    Nived N

    Stay connected:
    LinkedIn | YouTube | Blogs

    Was this answer helpful?
    If yes, please mark it as the solution by selecting the checkbox in the discussion thread.
    Your feedback motivates me to keep contributing. Thank you!

  • Suggested answer
    Ayush Purohit Profile Picture
    9 on at

    One method:


    1. Get Files Recursively

    • Use Get files in folder

      • Root = your monitored folder

      • Include subfolders = āœ…

      • Store result in FilesList


    2. Loop Through Files

    For Each CurrentFile in FilesList

    3. Filter Files with Both [ … ] and ( … )

    Use an If condition with regex match:

    \[[^\]]+\].*\([^)]+\)

    In PAD:

    If Regex.IsMatch(CurrentFile.Name, "\[[^\]]+\].*\([^)]+\)")

    This ensures the file has both square brackets and parentheses.


    4. Copy File to Staging

    Copy file(s)
    Source: %CurrentFile.FullName%
    Destination: %StagingFolder%\%CurrentFile.Name%

    5. Clean File Name

    Remove parentheses + contents

    \s*\([^)]*\)
    → ""

    Collapse double spaces (optional but recommended):

    \s{2,}
    → " "

    Trim spaces before extension (optional):

    \s+\.
    → "."
    • Store result in %CleanName%.

    In PAD, this looks like:

    Set Variable → CleanName = RegexReplace(CurrentFile.Name, "\s*\([^)]*\)", "")
    Set Variable → CleanName = RegexReplace(CleanName, "\s{2,}", " ")
    Set Variable → CleanName = RegexReplace(CleanName, "\s+\.", ".")

    6. Rename in Staging

    Rename file
    File: %StagingFolder%\%CurrentFile.Name%

    New Name: %StagingFolder%\%CleanName%

    7. Copy to Final Destination

    Copy file(s)
    Source: %StagingFolder%\%CleanName%
    Destination: %FinalFolder%\%CleanName%
  • JG-29031445-0 Profile Picture
    4 on at
    Thank you very much!

    I did something similar and it worked. The only thing that’s still missing is that I’d like to set the flow to run only on files that were created from yesterday onwards. I’m attaching what I wrote. Do you have an idea of what I’m missing? I really appreciate your professional assistance:
     
    Folder.GetFiles Folder: $'''C:\\Users\\Jacob\\Downloads\\×Ŗ×™×§×™×™×” יוצאת''' FileFilter: $'''*pdf''' IncludeSubfolders: True FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> Files
    Text.ConvertTextToDateTime.ToDateTimeCustomFormat Text: $'''2025-08-15''' CustomFormat: $'''yyyy-MM-dd''' DateTime=> StartDate
    LOOP FOREACH CurrentItem IN Files
        IF Create.Date > StartDate THEN
        END
        IF Contains(CurrentItem.Name, $'''[''', True) THEN
            File.Copy Files: CurrentItem.FullName Destination: $'''C:\\Users\\Jacob\\Downloads\\×Ŗ×™×§×™×™×Ŗ ביניים''' IfFileExists: File.IfExists.DoNothing CopiedFiles=> CopiedFiles2
            Text.Replace Text: CurrentItem.Name TextToFind: $'''[()]''' IsRegEx: True IgnoreCase: False ReplaceWith: $'''%''%''' ActivateEscapeSequences: False Result=> Replaced
            File.RenameFiles.Rename Files: CopiedFiles2[0] NewName: $'''%Replaced%ā€Ž''' KeepExtension: True IfFileExists: File.IfExists.Overwrite RenamedFiles=> RenamedFiles
            File.Copy Files: RenamedFiles Destination: $'''C:\\Users\\Jacob\\Downloads\\×Ŗ×™×§×™×™×Ŗ קליטה''' IfFileExists: File.IfExists.Overwrite CopiedFiles=> CopiedFiles
        END
    END
     

     
  • Suggested answer
    Nived_Nambiar Profile Picture
    18,138 Super User 2026 Season 1 on at
     
    Try this script
     
    SET FolderPath TO $'''%''%'''
    Folder.GetFiles Folder: FolderPath FileFilter: $'''*[*]*;*(*)*''' IncludeSubfolders: True FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> Files
    DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
    DateTime.Add DateTime: CurrentDateTime TimeToAdd: -1 TimeUnit: DateTime.TimeUnit.Days ResultedDate=> PrevDate
    LOOP FOREACH CurrentItem IN Files
        IF CurrentItem.CreationTime >= PrevDate THEN
            Text.Replace Text: CurrentItem.NameWithoutExtension TextToFind: $'''\\s*\\(.*\\)\\s*''' IsRegEx: True IgnoreCase: False ReplaceWith: $'''%''%''' ActivateEscapeSequences: False Result=> NewFileName
            File.RenameFiles.Rename Files: CurrentItem NewName: NewFileName KeepExtension: True IfFileExists: File.IfExists.Overwrite
        END
    END
    
     

    Thanks & Regards,
    Nived N

    Stay connected:
    LinkedIn | YouTube | Blogs

    Was this answer helpful?
    If yes, please mark it as the solution by selecting the checkbox in the discussion thread.
    Your feedback motivates me to keep contributing. Thank you!

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 376

#2
Valantis Profile Picture

Valantis 361

#3
David_MA Profile Picture

David_MA 294 Super User 2026 Season 1

Last 30 days Overall leaderboard