Solved

need help with a file copy program

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

759 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