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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -