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 / Question: How to delet...
Power Automate
Answered

Question: How to delete subfolders in a folder based on their contains files extension.

(0) ShareShare
ReportReport
Posted on by 34

For Example:
I have folder z.
it contains 3 subfolders a,b, and c
each subfolder contains many files.
I want to delete any subfolder, not containing text files.
(let's say "a" contains text files. so "a" will stay but "b" and "c" don't so they will be deleted.)

  • Verified answer
    ThomasFonn Profile Picture
    273 on at

    First, use the action "Get subfolders in folder" where you specify your base folder.
    Then use any loop, for example a "for each"-loop and iterate through all the subfolders

    Inside that loop, you can use "Get files in folder" and use the file filter by *.txt.

     

    The you can use an IF-condition and check if the files from the "Get files in folder" action count is = 0,

    and then finally delete that folder

  • mevo Profile Picture
    34 on at

    Hi, Thanks for the reply.

    I did as you said. but still, it's not working. can please point me out what doing wrong? I'm totally new at PAD.

    here is the Flow and screenshot too:

    Folder.GetSubfolders Folder: FolderPath FolderFilter: $'''*''' IncludeSubfolders: False FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Subfolders=> Subfolders
    LOOP FOREACH Subfolder IN Subfolders
    Folder.GetFiles Folder: Subfolder FileFilter: $'''*.txt''' IncludeSubfolders: True FailOnAccessDenied: True SortBy1: Folder.SortBy.NoSort SortDescending1: False SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> Files
    IF Files = 0 THEN
    Folder.Delete Folder: Subfolder
    END
    ENDflow.JPGexample file structure.JPG

     

  • Verified answer
    Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi.

    Try this in your IF condition:

     

    IF Files.Count = 0 THEN
    Folder.Delete Folder: Subfolder
    END

  • mevo Profile Picture
    34 on at

    It finally works!! thank you much. 

  • mevo Profile Picture
    34 on at

    Thank you so much. much appreciated.

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 Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 389

#2
11manish Profile Picture

11manish 345 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 308

Last 30 days Overall leaderboard