Solved

need help with a file copy program

Posted on 2011-03-24
2
315 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now