Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Files 1

Status
Not open for further replies.

EzehM

Programmer
Feb 27, 2003
86
GB
I have got a text file that contains the following information (delimited by “|”)

RBF|1.txt|04/01/2007 04:22:11
RBF|7.txt|04/01/2007 04:32:11
RBF|1.txt|02/01/2007 04:22:11
RBF|2.txt|03/01/2007 06:12:41
RAF|3.txt|07/01/2007 11:22:17
ROF|4.txt|05/01/2007 04:42:21
RBU|5.txt|04/01/2007 02:29:14


The first field contains the name of the folder, the second – the filename and the third – the creation date\time of the file.


I want to write this information into another file (ignoring files that are older than 7 days old from the date the application is run) in a format similar to this


-------------------------------------
|DIR|MO|TU|WE|TH|FR|SAT|SUN|
-------------------------------------
|RBF|0 |1 |1 |2 |0 |0 |0 |
-------------------------------------
|RAF|0 |0 |0 |0 |0 |0 |1 |
-------------------------------------
|ROF|0 |0 |0 |0 |1 |0 |0 |
-------------------------------------
|RBU|0 |0 |0 |1 |0 |0 |0 |
-------------------------------------

-------------------------------------
|TOT|0 |1 |1 |3 |1 |0 |1 |
-------------------------------------

TOTAL FILES 7


(There are 4 files for folder RBF, 1 created on Tuesday – 02/01/07, 1 created on Wednesday, 2 on Thursday and so on)


Please any help will be appreciated.

Thanks in advance





 
Aah. The unique combination of well-defined but simple requirements, no code, and the implicit assumption that someone else will code it for you.

Sounds a lot like homework...

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Steve,

This is the code so far (to write to the first file)

// get the name of the sub directory
string [] nacsC = dir.FullName.Split('\\');
string fName = nacsC[1];
foreach (FileInfo f in dir.GetFiles())
{
if (f.Extension == positiveAckExt)
{
// get starting and ending dates
DateTime todayDate = DateTime.Today;
DateTime fileDate = f.CreationTime;

TimeSpan timeDifference = todayDate.Subtract(fileDate);
double sevenDaysLater = timeDifference.Days;
Console.WriteLine("File Name - {0}: ", f.FullName);
Console.WriteLine("Creation Date - {0}: ", fileDate);
Console.WriteLine("Time difference {0}:", sevenDaysLater);

// we dont want to deal with files that are older than 7 days.
if (sevenDaysLater > 7)
continue;

// removed switch statement

tempF.Write(fName);
tempF.Write("|");
tempF.Write(f.FullName);
tempF.Write("|");
tempF.WriteLine(fileDate);

}

What is missing is the logic to write to the second file

Thanks


 
OK. I'd assumed that you were using the first file as input to create the second, rather than creating them both at the same time.

Suggest you use a Dictionary to hold the names of the directories, with the Value of each entry being an array of Int with seven entries, one for each day of the week. Then you can use the DayOfWeek property on your DateTime to index the values in the arrays, so you can increment them as you encounter each file.

This allows you to process as many directories as you like.

Then just iterate over the Dictionary to print out the table at the end.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Thanks Steve...Very helpful

Milton
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top