Solved

need help with a file copy program

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

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

830 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