' Region Description ' ' Name: SetArchive.vbs ' Author: Nilpo ' Website: http://www.nilpo.com ' Description: This script will move through all files in a provided ' folder and add an archive bit based on the file's age. ' ' EndRegion numDays = 90 strPath = "C:\Windows\Temp" Set objfso = CreateObject("Scripting.FileSystemObject") If objfso.FolderExists(strPath) Then 'Make sure folder exists Set objFolder = objfso.GetFolder(strPath) Set colFiles = objFolder.Files 'Enumerate files If colFiles.Count > 0 Then For Each objFile In colFiles Call SetArchiveFlag(objFile, numDays) 'Call subroutine for each file found. Next Else 'colFiles collection was empty WScript.Echo "No files in folder", objFolder.Path End If Else 'Folder path could not be found WScript.Echo "The specified folder", strPath, "does not exist" End If Sub SetArchiveFlag(objFile, numDays) On Error Resume Next 'Disable automatic error handling Err.Clear 'Clear the StdErr object before continuing dateFile = objFile.DateCreated 'Can also use DateLastModified or DateLastAccessed dateToday = Now() If dateFile <= dateToday Then daysOld = dateToday - dateFile 'Calculate file age If daysOld > numDays Then strFile = objFile.Path 'Retrieve file path for error handling or logging. Can be omitted if unused. If Not objFile.Attributes And 32 Then 'Check for existing Archive bit objFile.Attributes = objFile.Attributes And 32 'Set archive bit If Err.number <> 0 Then 'Check for error setting bit WScript.Echo Err.number, Err.Description, Err.Source, strFile End If End If End If Else WScript.Echo "Incorrect date stamp in", strFile End If End Sub