WebOct 21, 2013 · public List getLastFiles (string path) { List lastFiles = new List (); string [] files = Directory.GetFiles (path); foreach (string file in files) { FileInfo fileinfo = new FileInfo (file); if ( (DateTime.Now - fileinfo.LastWriteTime).TotalDays > 14) { lastFiles.Add (fileinfo); } } return lastFiles; } WebDec 5, 2011 · The easiest method is to define Object Lifecycle Management on the Amazon S3 bucket.. You can specify that objects older than a certain number of days should be expired (deleted). The best part is that this happens automatically on a regular basis and you don't need to run your own script.
Delete Old Files in a Folder in C# - EncodeDna.com
WebJul 31, 2024 · var filesToDelete = Directory.EnumerateFiles ("DirectoryPath") .Select (p => new {Name = p, LastWriteTime = File.GetLastWriteTime (p)}) .Where (f => f.LastWriteTime <= DateTime.Now.AddHours (-48)) .Take (100); Share Improve this answer Follow answered Jul 30, 2024 at 19:04 user729400 455 6 16 WebJun 18, 2015 · 0. try to write query for this and apply it in the code. var cutoff = DateTime.Now.AddDays (-10); var path = new DirectoryInfo (sourcePath); var query = path.GetFiles (filename, SearchOption.TopDirectoryOnly) .Where (fi => fi.CreationTime < cutoff); try the query, this may be easy and helpful to you. Share. rising hope church muncie
Move files to another directory which are older than a date
WebApr 24, 2012 · Maybe you wanted to use file.Name. Example: let's say directory is "c:\" and file points to "c:\myfile.log", your code will try to delete " c:/c:\myfile.log ". It's hard for me to guess what exactly you have in these variables. Correct replacement is suggested by @HenkHolterman: file.Delete (); Share Improve this answer Follow WebJan 5, 2010 · The first time the script is executed it will remove the timer files and it will take an hour to rebuild them (assuming you want 60 minutes of timer files) set -x # if the server is rebooted for any reason or this scripts stops we must rebuild the timer files from scratch find /yourpath/timer -type f -exec rm {} \; while [ 1 ] do COUNTER=60 ... WebAug 12, 2016 · Aug 12, 2016. 97.9 k. 0. 3. For demo purpose I have saved the latest file name in variable and printed on screen by using Console.Write () method. Using c#, we … rising hope clinical assistance llc