I need to check the files in the directory which all the files have the format like filename_20200219 and zip all the files which have the same date based on the date from the filename. How can this be done?
For example, a_20200219, b_20200219, c_20200220, d_20200220
The output after zipping should be:
a_20200219 and b_20200219 in a zip folder
c_20200220 and d_20200220 in another zip folder.
Thanks in advance.
Use Directory.EnumerateFiles(path) to retrieve all the files in a directory.
Than Path.GetFileNameWithoutExtension(filePath) to get its name.
Than split it on the ‘_’ with
var elements = fileName.Split('_');.
At position 1 there will be the date
var date = elements;.
So now you can group files having the same date.
I hope I was helpful