Solved

File Search

Posted on 2013-11-03
2
361 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 54

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 30

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

734 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