?
Solved

How do I copy files created on a selected date?

Posted on 2006-06-10
4
Medium Priority
?
182 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 93

Accepted Solution

by:
Patrick Matthews earned 1000 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 93

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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 how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses

765 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