cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mevo
Helper I
Helper I

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

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

2 ACCEPTED SOLUTIONS

Accepted Solutions
ThomasFonn
Advocate III
Advocate III

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

View solution in original post

JB_A
Frequent Visitor

Hi.

Try this in your IF condition:

 

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

View solution in original post

5 REPLIES 5
ThomasFonn
Advocate III
Advocate III

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

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

 

JB_A
Frequent Visitor

Hi.

Try this in your IF condition:

 

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

mevo
Helper I
Helper I

It finally works!! thank you much. 

Thank you so much. much appreciated.

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (3,495)