Solved

How do I copy files created on a selected date?

Posted on 2006-06-10
4
175 Views
Last Modified: 2010-04-30
I would like to have a script that prompts a user for a date, then copies files from c:\backup  ("ST*.txt" & "LR*.txt") created on the user supplied date to c:\logs_win\wms_data

Ideally, the user could type in the date, or click on an icon to bring up a calendar date selector.
 
Thanks,

Mike
0
Comment
Question by:spellm
[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
  • 2
4 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 250 total points
ID: 16877107
Assuming you set a reference to Microsoft Scripting Runtime...



Sub CopyFiles()

    Dim TheDate As Date
    Dim fso As Scripting.FileSystemObject
    Dim SourceFld As Scripting.Folder
    Dim fil As Scripting.File
   
    Const DestFldPath As String = "c:\logs_win\wms_data\"

    TheDate = InputBox("Enter creation date", "File Date", Format(Now, "d mmm yyyy"))
   
    Set fso = New Scripting.FileSystemObject
    Set SourceFld = fso.GetFolder("c:\backup")
    Set DestFld = fso.GetFolder("c:\logs_win\wms_data")
   
    For Each fil In SourceFld.Files
        If UCase(fil.Name) Like "ST*.TXT" Or UCase(fil.Name) Like "LR*.TXT" Then
            If Format(TheDate, "d mmm yyyy") = Format(fil.DateCreated, "d mmm yyyy") Then
                fil.Copy DestFldPath & fil.Name
            End If
        End If
    Next
   
    Set fil = Nothing
    Set SourceFld = Nothing
    Set fso = Nothing
   
    MsgBox "Done"
   
End Sub
0
 

Author Comment

by:spellm
ID: 16892638
How would I display a count of the number of files that were copied?
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 16892950
Like this:

Sub CopyFiles()

    Dim TheDate As Date
    Dim fso As Scripting.FileSystemObject
    Dim SourceFld As Scripting.Folder
    Dim fil As Scripting.File
    Dim Counter As Long

    Const DestFldPath As String = "c:\logs_win\wms_data\"

    TheDate = InputBox("Enter creation date", "File Date", Format(Now, "d mmm yyyy"))
   
    Set fso = New Scripting.FileSystemObject
    Set SourceFld = fso.GetFolder("c:\backup")
    Set DestFld = fso.GetFolder("c:\logs_win\wms_data")
   
    For Each fil In SourceFld.Files
        If UCase(fil.Name) Like "ST*.TXT" Or UCase(fil.Name) Like "LR*.TXT" Then
            If Format(TheDate, "d mmm yyyy") = Format(fil.DateCreated, "d mmm yyyy") Then
                fil.Copy DestFldPath & fil.Name
                Counter = Counter + 1
            End If
        End If
    Next
   
    Set fil = Nothing
    Set SourceFld = Nothing
    Set fso = Nothing
   
    MsgBox "Done; copied " & Counter & " files"
   
End Sub


Patrick
0
 

Author Comment

by:spellm
ID: 16895422
Great!  Thanks a lot.
0

Featured Post

Independent Software Vendors: 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

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.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

730 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