Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

File Search

Posted on 2013-11-03
2
Medium Priority
?
369 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 57

Accepted Solution

by:
Bill Prew earned 1000 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 1000 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…
Suggested Courses

722 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