Solved

File Search

Posted on 2013-11-03
2
356 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 53

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

831 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