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™
on
Hi,
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.

Thanks
Comment
Watch Question

Do more with

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

Commented:
Hi,

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

https://www.experts-exchange.com/questions/25063189/file-listing-in-Excel-VBA-Script.html#a26340696

Regards,
D Patel
Test your restores, not your backups...
Top Expert 2016
Commented:
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
    Next

    ' 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
        Next
    End If
End Sub

Open in new window

~bp

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