web applications - how to delete file according to its date and time in asp.net c# -
I search a lot on google, I get some feedback, but I do not know what I want for what I want It seems that I have 5 files for the same file, for the same date: 1 file - 1 MB 2 file = 2 MB 3G file - 3 MB 4 files - 4 Mb 5th file - 5 MB < P> Now when I click on my button it will remove all files except 5 MB due to its size.
First I want to search the files according to the date in a folder and afterwards leaving the file and removing all the files for that special date, size.
I do not want the code I want to be used in this project. Thank you in advance
DirectoryInfo you can get all the files Obtain the maximum size file based on the specified path,
File.Length property, and then delete it like this:
DirectoryInfo di = new DirectoryInfo ("C: \") ; Var files = di.GetFiles (); var maxFileSize = files.Max (r = & gt; r.Length); foreach files (filesInfo file) where (R = & gt; R. lang & lt; maxFileSize)) {File.Delete ();}
Comments
Post a Comment