Inline Function for Delete All Files in a Folder

Hi,

How to delete all file in folder?
I need to check folder if the file is exists and delete all the files in the folder.

Hi @Gowthaman_Subramanian

Create a Boolean datatype variable Bool_FileExist.

- Assign -> Bool_FileExist = If(Directory.GetFiles("Give Folder Path here").Count>=1, True, False)

→ Take an If activity to check the condition,

- Condition -> Bool_FileExist = True

→ Inside then block insert the For each file in folder activity to iterate the each file in the folder. Output is CurrentFile.
→ Inside For each file in folder activity insert the Delete file activity and give CurrentFile.toString as input.

Check the below workflow for better understanding,

Hope it helps!!

1 Like

Hie @Gowthaman_Subramanian for this you may go with this approach hope it will work on your case …
i"m attaching shreeshot for this method
Folder path - variable is string


to get file path - variable is array of string
image
use a for each - to itreate all the files from the folder one by one

use a file exists activity and save their output
output variable type - boolean
and if it is true -
then inside then branch use (Delete File Activity)
image

Hope it work for you .
mark this solution if you find it work for you
cheers Happy Automation :grinning:

1 Like

@Gowthaman_Subramanian

Do you want to delete a single file in the folder or all files in a folder.

I want to delete all the file in that folder.

Have you tried the process steps that I have mentioned in the above post. It not worked for you…? @Gowthaman_Subramanian

Thanks Mahesh. Yes I tried, it is working.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.