vb script to find all the files and subfolders in a directory(folder) modified 'x' minutes ago

anamika sharma
anamika sharma used Ask the Experts™
I need a vb script that will list down all the files in the given folder and its subfolder that are modified 'x' minute ago say (20min ago) compared to localtime or system time.Please help me out if you have any idea of how to do this because I am very much new to vb script.

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
D PatelD Patel, Software Engineer


You can find the similar question at the link below (EE forum answered):


D Patel
Test your restores, not your backups...
Top Expert 2016
Here's a pretty simple starting point for you that recursively lists all files in a base folder and subfolders newer than 20 minutes.  Save as a VBS, adjust the path near the top to your base folder and then run as follows from a command prompt:

cscript EE29015360.vbs

' Specify base folder to list, and age in minutes of files to list
Const strBaseDir = "C:\Temp"
Const intAge = 20

' Display current date / time
Wscript.Echo "Current date / time = " & Now

' Create file system object
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

' List new files recursively
ListFiles objFSO.GetFolder(strBaseDir)

Sub ListFiles(objFolder)
    On Error Resume Next

    ' List any files newer than specified age
    For Each objFile In objFolder.Files
        If DateDiff("n", objFile.DateLastModified, Now) < intAge Then
            ' Display file path to console
            Wscript.Echo objFile.Path
        End If

    ' See if we were able to access this folder, if not don't recurse into it
    If Err.Number = 0 Then
        ' List any newer files in any subfolders of this one
        For Each objSubFolder In objFolder.Subfolders
            ListFiles objSubFolder
    End If
End Sub

Open in new window


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial