title: VBAScript to delete items from folder
body: <p>I'm new to VBScripting and have completely no knowledge on how to code but however i understand the basics of VBScripting.</p>
  
  <p>I tried using the search function to find similar cases to mine but it doesn't have what i need.</p>
  
  <p>I would really appreciate any help as my project is due soon.</p>
  
  <p>Scenario:</p>
  
  <p>I need to delete jpeg files that are more than 3months old that is in a directory with lots and lots of subfolders within each other. Furthermore there are 4 folders in the directory that i must not delete or modify.</p>
  
  <p>How i manually did it was to navigate to the mapped drive, to the folder, use the "Search 'Folder'" from the window and type in this "datemodified:‎2006-‎01-‎01 .. ‎2013-‎08-‎31".</p>
  
  <p>It will then show all the folders and subfolders and excel sheets within that folder, i'll then filter the shown list by ticking jpeg only from Type.</p>
  
  <p>Code:
  '<strong><em>*</em>**<em>*</em></strong> Start of Code <strong><em>*</em>**<em>*</em>**<em>*</em>**<em>*</em></strong></p>
  
  <pre><code> Option Explicit 
   On Error Resume Next 
   Dim oFSO, oFolder, sDirectoryPath 
   Dim oFileCollection, oFile, sDir 
   Dim iDaysOld 
  </code></pre>
  
  <p>' Specify Directory Path From Where You want to clear the old files </p>
  
  <pre><code> sDirectoryPath = "C:\MyFolder" 
  </code></pre>
  
  <p>' Specify Number of Days Old File to Delete</p>
  
  <pre><code> iDaysOld = 15
  
   Set oFSO = CreateObject("Scripting.FileSystemObject") 
   Set oFolder = oFSO.GetFolder(sDirectoryPath) 
   Set oFileCollection = oFolder.Files 
  
  For each oFile in oFileCollection
  </code></pre>
  
  <p>'This section will filter the log file as I have used for for test case 
  'Specify the Extension of file that you want to delete 
  'and the number with Number of character in the file extension </p>
  
  <pre><code>If LCase(Right(Cstr(oFile.Name), 4)) = "jpeg" Then
  
      If oFile.DateLastModified &lt; (Date() - iDaysOld) Then 
      oFile.Delete(True) 
      End If 
  
  End If   
  Next 
  
  Set oFSO = Nothing 
  enter code here`Set oFolder = Nothing 
  enter code here`Set oFileCollection = Nothing 
  enter code here`Set oFile = Nothing 
  </code></pre>
  
  <p>'<strong><em>*</em>**<em>*</em>***<em></strong> End of Code <strong></em>**<em>*</em>**<em>*</em>****</strong></p>
  
  <p>I need to set an path that must be excluded + go through sub folders.</p>
  
  <p>I'd like to thank you in advance for helping me out.</p>
  
  <p>Thanks,</p>