Solved

File Search

Posted on 2013-11-03
2
346 Views
Last Modified: 2013-11-04
Hello Experts,

I have a folder "D:\Client FTP Folders\" (spaces included) and I am wondering how can I scan its subfolders for files that meet the following criteria:

(file extension = .ORD) AND (file created before 11/03/2013 7:32:24 PM)

Thank you
0
Comment
Question by:APD_Toronto
2 Comments
 
LVL 51

Accepted Solution

by:
Bill Prew earned 250 total points
ID: 39620686
Okay, here's script that should do what you describe. Adjust the settings near the top and give it a test.

' Define the folder to scan, and the age of files to locate
strBaseDir = "D:\Client FTP Folders"
datBefore = CDate("11/03/2013 7:32:24 PM")

' Create a dictionary to hold the list of extensions to list
Set dicExt = CreateObject("Scripting.Dictionary")
dicExt.CompareMode = vbTextCompare
dicExt.Add "ord", 0

' Set up filesystem object for usage
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Look for files
FindFiles objFSO.GetFolder(strBaseDir)

' Subroutine (recursive) to search for files to delete
Sub FindFiles(objFolder)
   On Error Resume Next

   ' Look at all files in this folder
   For Each objFile In objFolder.Files
       ' Make sure it's one of the extensions we want to delete
       If dicExt.Exists(objFSO.GetExtensionName(objFile.Path)) Then
          ' See if it's old enough to display
          If objFile.DateCreated < datBefore Then
             WScript.StdOut.WriteLine objFile.Path & ", " & objFile.DateCreated
          End If
       End If
   Next

   ' See if we were able to access this folder, if not don't recurse into it
   If Err.Number = 0 Then
       ' Recursively drill down into subfolder
       For Each objSubFolder In objFolder.SubFolders
           FindFiles objSubFolder
       Next
   End If
End Sub

Open in new window

~bp
0
 
LVL 29

Assisted Solution

by:anarki_jimbel
anarki_jimbel earned 250 total points
ID: 39620697
Something like below (I used my date for testing :)):

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim path As String = "C:\\temp"
        Dim topdir As New IO.DirectoryInfo(path)
        Dim fileList As New List(Of FileInfo)
        findFileInfosRecursively(topdir, fileList)

        For Each file As FileInfo In fileList
            Debug.WriteLine(file.FullName & " / " & file.LastWriteTime.ToLongDateString)
        Next

    End Sub

    Sub findFileInfosRecursively(ByVal dir As IO.DirectoryInfo, ByVal fileList As List(Of FileInfo))
        Dim files() As FileInfo = dir.GetFiles("*.log")
        For Each afile As FileInfo In files
            If afile.LastWriteTime < New Date(2013, 7, 1) Then
                fileList.Add(afile)
            End If
        Next

        Dim dirs() As DirectoryInfo = dir.GetDirectories
        For Each adir As DirectoryInfo In dirs
            findFileInfosRecursively(adir, fileList)
        Next

    End Sub

Open in new window

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now