Copy files by date modified
Copy files by date modified
Copy files by date modified
Copy files by date modified
Copy files by date modified
Copy files by date modified Copy files by date modified Copy files by date modified Copy files by date modified Copy files by date modified Copy files by date modified Copy files by date modified Copy files by date modified
Copy files by date modified Copy files by date modified
Copy files by date modified
Go Back  Xtreme Visual Basic Talk > > > Copy files by date modified


Reply
 
Thread Tools Display Modes
  #1  
Old 03-18-2011, 10:49 AM
leviticus leviticus is offline
Newcomer
 
Join Date: Mar 2011
Posts: 5
Default Copy files by date modified


Hello all,

I'm new here. Let me start by saying, I'm not a student looking for someone to write my homework and let me put my name on it. I have a computer science degree, but have take much time off from programming since college and am rusty.

I'm helping with a project for work; completely unrelated to my actual job. I'm trying to create a program with VS2008 that will:


- Allow me to copy 30 newest .txt files from a folder by looking at date modified. This can be hardcoded or a text box that prompts the user for how many days of files to pull. so...

'get files
My.Computer.FileSystem.GetFiles(D:\sourceFolder)
'put files into an array
filesArray()
'look at the current date and decrement 30 times???
For Date.Now step -1
'copy 30 of the newest .txt files
My.Computer.FileSystem.CopyFiles(D:\destinationFolder, filesArray)
next


When the user selects a "transfer files" button, the program will automatically create a new folder in a directory specified by me, copy all files, then create a zipped folder after all files have been copied.

I have all working except the portion above in bold. Any help would be great!!!
Thanks
Reply With Quote
  #2  
Old 03-21-2011, 05:22 PM
Orca44 Orca44 is offline
Centurion
 
Join Date: Nov 2004
Location: Cape Town, South Africa
Posts: 124
Default

Welcome to the forum.

First off, I would recommend using the date-related functions for that since dates can get surprisingly complicated. Thus I would use the following for your problem :
Code:
Dim targetDate As DateTime = DateTime.Now.AddDays(-30)
To identify the thirty most recently modified .txt files, you would have to loop through all the .txt files in the directory, storing the top 30 modified dates along with the file name.
You can check the modified date by using System.IO.File.GetLastWriteTime(), I believe.

There might be a more elegant way of solving the problem, but this will probably get you where you're going.

Let me know if my explanation isn't clear of if you encounter any further hitches.
Reply With Quote
  #3  
Old 03-22-2011, 10:00 AM
leviticus leviticus is offline
Newcomer
 
Join Date: Mar 2011
Posts: 5
Default

Much thanks for the help.

As soon as I get some down time, I'll work this code into my program and let you know how it goes.
Reply With Quote
  #4  
Old 03-22-2011, 10:08 AM
leviticus leviticus is offline
Newcomer
 
Join Date: Mar 2011
Posts: 5
Default

Another thought I had...

In regards to copying files; would it be possible/easier to use a date picker box?

The user would pick a date on the calendar, the program would compare the date selected to date.now and transfer all files withing date range????
Reply With Quote
  #5  
Old 03-22-2011, 04:40 PM
Orca44 Orca44 is offline
Centurion
 
Join Date: Nov 2004
Location: Cape Town, South Africa
Posts: 124
Default

Yes, that is a good idea since that DateTimePicker was created for the very purpose of selecting a date. Just keep in mind that unless you choose a custom format for the datepicker, its' value property will just be a date, or more precisely a date with the time of 0:00, or twelwe in the morning.
Reply With Quote
Reply

Tags
copy files, date range


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Copy files by date modified
Copy files by date modified
Copy files by date modified Copy files by date modified
Copy files by date modified
Copy files by date modified
Copy files by date modified Copy files by date modified Copy files by date modified Copy files by date modified Copy files by date modified Copy files by date modified Copy files by date modified
Copy files by date modified
Copy files by date modified
 
Copy files by date modified
Copy files by date modified
 
-->