Solved

need help with a file copy program

Posted on 2011-03-24
2
318 Views
Last Modified: 2012-05-11
I need to be able to move a group of files from one location to another, and after verifying that the counts match, delete the original.  That part is easy.  The wrinkle is that I only want to get files where the date modified is for a certain month. So I need to move all the files from January to the new folder and not touch Feb. dated files.

I'm currently using the below code but how can I modify it to bring back just those within a given date range (or month)
For Each f In lstFolders
                For Each sf In f.lstSubFolders
                    BeginFileCnt = System.IO.Directory.GetFiles(f.rootPath & "\" & sf).Length
                    For Each fi As FileInfo In New IO.DirectoryInfo(f.rootPath & "\" & sf).GetFiles("*.*")
                        fi.CopyTo(DestinationPath & "\" & f.rootFolder & "\" & sf & "\" & fi.Name)
                    Next
                    EndFileCnt = System.IO.Directory.GetFiles(DestinationPath & "\" & f.rootFolder & "\" & sf).Length
                Next
            Next

Open in new window

0
Comment
Question by:rutledgj
[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 4

Assisted Solution

by:MaximumIQ
MaximumIQ earned 100 total points
ID: 35207938
add another If, Then statment inside your loop and make it something like

If month(sf.datelastmodifield) = month(now) and year(sf.datelastmodified)=year(now) then

your code

end if

The syntax would varry though depending on the version of .NET you're using and I would also need to see your declarations to give you working code
0
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 400 total points
ID: 35207974
For Each f In lstFolders
                For Each sf In f.lstSubFolders
                    BeginFileCnt = System.IO.Directory.GetFiles(f.rootPath & "\" & sf).Length
                    For Each fi As FileInfo In New IO.DirectoryInfo(f.rootPath & "\" & sf).GetFiles("*.*")
                        'Here you need to check fi.LastWriteTime. For example, you may got 2 date variables,
                        'named periodStart and periodEnd, and check LastWriteTime with these 2 variables
                        If fi.LastWriteTime >= periodStart AndAlso fi.LastWriteTime <= periodEnd Then
                            fi.CopyTo(DestinationPath & "\" & f.rootFolder & "\" & sf & "\" & fi.Name)
                        End If
                    Next
                    EndFileCnt = System.IO.Directory.GetFiles(DestinationPath & "\" & f.rootFolder & "\" & sf).Length
                Next
            Next

Hope that helps.
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

739 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