Solved

File Search

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

740 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