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

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.

anamika sharmaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

D PatelD Patel, Software EngineerCommented:

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


D Patel
D PatelD Patel, Software EngineerCommented:
Bill PrewIT / Software Engineering ConsultantCommented:
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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.