Delete empty files in a folder

I want to delete empty files from a folder. Like empty text file excel file. how it can be achieved.

Use Invoke Code activity and use a VB.net code something like below:

Dim info As New FileInfo("C:\Amalendu\Projects\NOV\AMS\Testing Team\Docs\New Text Document.txt")
Dim length As Long = info.Length

If(length = 0)
	info.Delete()
End If

Now one thing you need to do before it is get all the files inside a directory and loop through those files with the above code.

Hi @Shashi123

Alternative way strictly with UiPath acitivties:
Delete empty files.xaml (8.9 KB)

@loginerror will it delete empty folder and sub folders too??

It has been a while since I made this one. From the screenshots here, I can see that it lists only the files in a directory (as this was the requirement here) :slight_smile:

You should be able to easily adapt the code though, you will simply have to research the Directory class :slight_smile:

However, I don’t see the point to loop through all the subfolders to delete them. You only need to delete the root folder once, no?

Only if it is blank, and for that all subdir should be empty and deleted then only root folders should get deleted.