How to zip files with a certain extension and then delete those files

I have folder like this with two types of files

One type is xls and other is xlsx. I need to only pick the files with xls extension and then zip them and lastly delete those files

How to achieve this

Hi @Ishan_Shelke,

Use this motherd


stYourPath = “D:\New folder”




Just move .XLS files to one temporary file and just pack it with zip.

Hi @Ishan_Shelke

First, you can create list of all files from your directory by using Directory.GetFiles method by:

Directory.GetFiles(strPathToFolderWithFiles, "*.xls").ToList()

Then, having those files saved in a list, you can create a separate folder and move all those files from the first folder, to the newly created one.

In the end, in order to create final .zip file, you can follow the following steps: