How to delete multiple files

I have some files with different extensions that I need to delete. I tried to delete multiple files adding a * in the path for the Delete activity like:


But I get an error message.

sortIssues has thrown an exception
Message: Illegal characters in path.

What is the right way to do it.


1 Like

Hi @selrac,

Please follow the example that I have attached:
Main.xaml (7.2 KB)


I see. You have to look through the files and delete. Would it be possible to use Visual Basic for this type of actions?

Hi @selrac,

To be honestly I don’t know, but why wouldn’t use the approach that I have suggested? I don’t get your point.


I would go with Mr. @acaciomelo 's solution , but if you want in a single line you can try somethinking like below

Array.ForEach(Directory.GetFiles(@"c:\MyDir\"), File.Delete);


Wanna add some points here: @selrac

if you will use this:

When directory will be empty then it will return an error so keep that in mind and as a workaround you can handle it by using files count with if condition.


Directory.GetFiles(“<your path>”).Length > 0



I would be tempted to use the Path.GetExtension method to determine whether or not you want to delete the file as it sounds like you only want to delete certain ones…

E.g. get all files in the directory then loop through using the above to check the file extensions and delete them if appropriate.

1 Like

Long Path Tool allows delete, copy or rename long path files.

1 Like

Hey @Edwards_Crofer
why you wanna depend on third party tool if you can make things with code. of some lines :slight_smile:


1 Like

Can you pls provide .xaml file for this…

Hi All,

refer below xaml file to delete all files from the folder.

Main.xaml (10.1 KB)


1 Like

Hi, arivu96!

Thank you so much for sharing the xaml file!

However, i have problem, when I add the delete activity to if window and add item as the path just as you did, it gives me an error that “object cannot be converted to string”.
I’m a newbie since a few weeks back and i still haven’t gotten the hang of all the variable type and how they work.
Would you please tell me what the solution might be to this error.

Thank you

You’ve probably already figured this out, but in case others have the same result I’ll help…

In UiPath, when you create a For Each statement, the default type is Object. You have to either change the TypeArgument in properties to String, or change the item to item.toString