directory - Deleting Directories by CreationTime in C# -
i have c# application in there requirement delete files date created older today’s date. how can achieve this?
i had search in google find out sample code. decide create 1 , post here.if want delete older files directory , can use below method. if have queries on please let me know well, happy you.
public void folderdelete() { directoryinfo d = new directoryinfo(configurationmanager.appsettings["<path>"]); if (d.exists) { //get directories path string[] folders = directory.getdirectories(d.tostring()); foreach (var item in folders) { directoryinfo info = new directoryinfo(item); //it purge 14 days older directories if (info.creationtime < datetime.now.adddays(-14)) { info.delete(true); } } } else { console.writeline("there no 14 days older files."); } }
this useful , simple use.i have tried above method.could 1 of have idea, please share me.
if have windows, forfiles may want.
http://technet.microsoft.com/en-us/library/cc753551(ws.10).aspx
Comments
Post a Comment