How can I delete all files from a directory?

I know there is the Delete File activity, but it only works for one file at a time. I want to be able to select the directory and delete all files in it. I haven’t found an actvity that does that. So far the only solution I ahve found is to use List diretory files and then creating a counter that deletes one file at a time as long as the counter is less than the number of files in the directory.

Is there a different approach I can use?

Hi @cris-dsc

I hope you are doing well!

Yes! I am sure you can delete all the files with one activity. Have you tried to use command prompt. If not, give it a try. It will solve your issue.

Share your feedback on this. If it not solves your problem, we can find another way for it.

Have a great day!

Best Regards,
Muhammad Hayyan Khan

I’ve tried using the del * command to delete all files from the folder, but I’m getting an error because the system asks me if I’m sure I want the files to be deleted and I don’t know how to use command prompt activity to answer ‘yes’.

Can you please share the screenshot of the process you mentoined above. So that I could tell you another method to solve the issue.

Hi @cris-dsc!

I see you’ve used the del * command successfully to delete all the files inside a folder, but it’s prompting you for confirmation.

You can add a /q parameter to that command to execute it in “quiet mode” - which means that you will not be prompted for confirmation.

So your full command would be del <directory>\* /q (where <directory> is of course the directory that contains all the files you want to delete).

Please let me know if this works for you! You can also mark my answer as a Solution.

1 Like

Could you inform us, @cris-dsc, if the aforementioned solutions provided by @Ivan_Ramos were effective for you?