473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

GEt last 7days file from a folder

115 100+
i need to get only last 7days files from a folder. using vb.net.

in my C drive i have a folder called LogFiles, and inside that logfiles folder i have more than 15-25 log files were there. and the name of each file will be the date in which it created.

eg: 20070607.log (this file created today).
eg: 20070503.log (created last month 3rd).

so i need to get the last 7 days log file by checking with current date.

how can i find the last 7days files from this folder. if you have any idea how to do this please let me know. if example is there, it will be very helpful to me.

thanks in advance.
Jun 7 '07 #1
1 1399
akipng
7
Hello

Here is example I done to search for files by its filename coded date.

Expand|Select|Wrap|Line Numbers
  1.  
  2. System.Collections.ArrayList allMatches = new System.Collections.ArrayList();
  3. string[] files = System.IO.Directory.GetFiles(".", "*.log");
  4. // gets fullpath or relative path files
  5. foreach (string fileFullName in files)
  6. {
  7.     // get only RRRRMMDD from filename
  8.     string fileName = fileFullName.Substring(fileFullName.LastIndexOf('\\') +1,8); // I'm trying to make // only other way and I got some spaces here
  9.     int year =Convert.ToInt32(fileName.Substring(0, 4));
  10.     int month = Convert.ToInt32(fileName.Substring(4, 2)); // if you read us time switch month for days
  11.     int day = Convert.ToInt32(fileName.Substring(6, 2));
  12.     DateTime fileDT = new DateTime(year, month,day);
  13.     TimeSpan searchMargin = new TimeSpan(7, 0, 0, 0);
  14.     TimeSpan fileAge = DateTime.Now - fileDT;
  15.     if (fileAge < searchMargin)
  16.     {
  17.         allMatches.Add(fileFullName);
  18.     }
  19. }

cheers
AkipNG
Jun 7 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: JPM III | last post by:
I wrote a PHP script that allows me to post HTML entries to files on my server without going through FTP, yadda yadda. It works fine, and last night it updated both files properly. Today, it...
3
by: George0726 | last post by:
This happens regardless of the Version of Access. Users accessing a database on a shared folder get the "Couldn't use <filename>; file already in use." Everyone without exception has access to...
1
by: RC | last post by:
How easy would it be for me to send the result from this script to a txt or csv file. I also want to make sure it is getting the results from all Domain Controllers in the domain. The LLTS may vary...
3
by: sklamp | last post by:
Hello evryone I hope, that I corectly placed this question. For example: I have a folder with name "yName" and this folder includes binary files, like "Testing.ov", which cames from simulation. When...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.