private void button6_Click(object sender, System.EventArgs e) { System.Collections.Specialized.StringCollection myFileCollection = new System.Collections.Specialized.StringCollection(); string myPath = @"c:\it\"; string myFileName = "*.*"; foreach (string myFile in System.IO.Directory.GetFiles(myPath, myFileName)) { myFileCollection.Add(myFile); } MessageBox.Show(myFileCollection.Count.ToString()); foreach(string myFile in myFileCollection) { MessageBox.Show(this.myDataDiff(System.IO.File.GetLastWriteTime(myFile), System.DateTime.Now).ToString()); } } private long myDataDiff(System.DateTime date1,System.DateTime date2) { long TicksPerDay = 864000000000; long diff = date2.Ticks - date1.Ticks; long days = diff/TicksPerDay; return days; }Hope this helps.
>.... >ofso = CreateObject("Scripting.FileSystemObject") >..... > >Sub CleanBackup(ByVal BackupDirectory) > 'erase files older than 15 days back > If Not ofso.FolderExists(BackupDirectory) Then > Exit Sub > End If > With ofso.GetFolder(BackupDirectory) > If .Files.Count > 0 Then > For Each oitem In .Files > If DateDiff(DateInterval.Day, oitem.DateCreated, Now) > 14 Then > oitem.delete() > End If > Next > End If > End With >End Sub > >Sub TestCleanBackup(ByVal BackupDirectory) > 'erase files older than 15 days back > If Not System.IO.Directory.Exists(BackupDirectory) Then > Exit Sub > End If > > Dim aFiles() As String > > aFiles = System.IO.Directory.GetFiles(BackupDirectory, "*.*") > For ia = 0 To aFiles.Length - 1 > If DateDiff(DateInterval.Day, System.IO.File.GetCreationTime(aFiles(ia)), Now) > 14 Then > System.IO.File.Delete(aFiles(ia)) > End If > Next >End Sub >