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 / 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.)

I have the same question (0)
  • 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
    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

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

#2
Tomac Profile Picture

Tomac 321 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard