Solved

need help with a file copy program

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
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 …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

813 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

11 Experts available now in Live!

Get 1:1 Help Now