How to delete all files that contain xlsx in their names?


I would like to delete all files in a folder that contain “xlsx” in their names.

What would be the best way to go about that?


@Kamalen_Reddy Do you want to delete xlsx file types only or the file names which contain xlsx ?

The Directory.getfiles Method has a filter argument available. So for xlsx Extension give a try on *.xlsx. for xlsx in Name give a try on *xlsx*

All file names which contain xlsx. Including ans excluding their file extensions.


You can check as below

If you want to check what item is return, check below, it will return full path of the file

Hope this helps


1 Like

Thank you All,

I went with the following approach:



> ExcelFilePath = Directory.GetFiles(Environment.CurrentDirectory)


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