Wrox Programmer Forums
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 8th, 2007, 05:49 AM
Registered User
 
Join Date: Nov 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Text Files

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




 
Old January 9th, 2007, 04:33 AM
Registered User
 
Join Date: Nov 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No gurus?

:-(

 
Old January 9th, 2007, 11:14 AM
Registered User
 
Join Date: Dec 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to c010depunkk
Default

What kind of help do you want?
A finished app? Or do you have specific questions?
 
Old January 9th, 2007, 12:45 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am not a guru, and this isn't a guru level problem.
How far have you gotten with this?
Have you written any pseudo code?
Do you know how to read and write from files?
Do you know how to use regular expressions?
Have you worked with ArrayLists?
You are describing a very basic problem that requires a knowledge of a few basic concepts. Rather than write your whole application, people who are willing to help usually want to help with a specific problem, not something as all-encompassing as this. So, what part of this are you actually having trouble with?

Woody Z
http://www.learntoprogramnow.com
 
Old January 12th, 2007, 05:24 AM
Registered User
 
Join Date: Jan 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

First thing for ease create a
struct sFInfo
{
 string sFolder;
 string sFileName;
 string sDate;
}
First thing is Open the file using a StreamTextReader or for that matter many other readers exist
After Opening the file successfully meaning check for null
Loop until End of File
ArrayList GetFileInfo(string sFName)
// sFName is the Text file which contains info you want to extract
{
string[] sArr;
sFInfo Fobj;
string sLine;
ArrayList alFileLst = new ArrayList();

while(!sr.EOF)
{
 sLine=sr.ReadLine();

 sArr= sLine.Split('|');
 FObj.sFolder=sArr[0];FObj.sFileName=sArr[1];
 FObj.sDate=sArr[2];
 alFileLst.Add(fo);
}
sr.Close();
sr=null
return alFileLst;
}

public void InfoWriter(ArrayList alFileList, string sCutoffDate)
{
In this method you read the arrayList one object at a time
 sDate is of importance within the structure as you loop through the
 ArrayList what you do is first separate the Date and time use the split with blank delimiter. (In the previous method I have used '|' as delimiter) then separate date into month and day and compare it use stringBuilder to create a format like you want. In case of a problem let me know )
All the best

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

 
Old January 12th, 2007, 11:57 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by DriveU
 First thing for ease create a ...
DriveU: Your post is not very clear, and seems to be missing a lot of information. What exactly are you trying to show?

Woody Z
http://www.learntoprogramnow.com
 
Old January 12th, 2007, 01:01 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I agree with woody, this is not a guru level problem and what you are trying to do is some what elementary (IMHO) so to reiterate woody, what are you trying to show and what exactly is your problem here. What does your code DO and what DOESNT it do?

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile
 
Old January 13th, 2007, 05:47 AM
Registered User
 
Join Date: Jan 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My intent was not to write a complete program just give a direction one can take in a situation like this.
My solution will work for sure if done properly.
Maybe you have a better solution but my solution will work if implemented properly.
First thing is to separate information of interest with reference to the text file
Second thing is to perform a check to isolate data based on input parameters using StringBuilder build the format and as we go about doing this accumulate results and finally show the formatted strings.

 
Old January 13th, 2007, 12:43 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by DriveU
Code:
First thing for ease create a 
struct sFInfo
{
 string sFolder;
 string sFileName;
 string sDate;
}
First thing is Open the file using a StreamTextReader or for that matter many other readers exist
After Opening the file successfully meaning check for null
Loop until End of File
ArrayList GetFileInfo(string sFName) 
// sFName is the Text file which contains info you want to extract
{
string[] sArr;
sFInfo Fobj;
string sLine;
ArrayList alFileLst = new ArrayList();

while(!sr.EOF)
{
 sLine=sr.ReadLine();
 
 sArr= sLine.Split('|');
 FObj.sFolder=sArr[0];FObj.sFileName=sArr[1];
 FObj.sDate=sArr[2];
 alFileLst.Add(fo);
}
sr.Close();
sr=null
return alFileLst;
}

public void InfoWriter(ArrayList alFileList, string sCutoffDate)
{
 My intent was not to write a complete program just give a direction one can take in a situation like this.
My solution will work for sure if done properly.
Maybe you have a better solution but my solution will work if implemented properly.
First thing is to separate information of interest with reference to the text file
Second thing is to perform a check to isolate data based on input parameters using StringBuilder build the format and as we go about doing this accumulate results and finally show the formatted strings.
Okay. Have fun.

Woody Z
http://www.learntoprogramnow.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare 2 Text Files mollem VBScript 5 April 16th, 2016 09:35 AM
Reading text files senthilreddy ASP.NET 2.0 Basics 1 May 22nd, 2007 08:32 AM
comparing Two text files rajkumar007 Classic ASP Basics 0 October 15th, 2005 07:22 AM
Comparing Two Text Files rajkumar007 Classic ASP Professional 0 October 14th, 2005 10:01 AM
Regarding " reading text files" spraveens Classic ASP Basics 1 October 14th, 2003 07:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.