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

Hello Shashi,
In this video I do a lot of stuff with Files:
At minute 11 I use FileInfo this will help you to check for empty files:

6:00 Move files to do Rename
6:55 Delete files
8:15 Delete only PNG files
8:55 Delete all the files except PNG files
9:55 Move files
11:10 Delete files that are older than 2 weeks
Cristian Negulescu