|
|
 |
| 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers questions, win occasional prizes given to our best members, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
|
 |
|
|
 |

January 8th, 2007, 04:49 AM
|
|
Registered User
|
|
Join Date: Nov 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

January 9th, 2007, 03:33 AM
|
|
Registered User
|
|
Join Date: Nov 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
No gurus?
:-(
|

January 9th, 2007, 10:14 AM
|
|
Registered User
|
|
Join Date: Dec 2006
Location: , , Germany.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
What kind of help do you want?
A finished app? Or do you have specific questions?
|

January 9th, 2007, 11:45 AM
|
|
Friend of Wrox
|
|
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

January 12th, 2007, 04:24 AM
|
|
Registered User
|
|
Join Date: Jan 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

January 12th, 2007, 10:57 AM
|
|
Friend of Wrox
|
|
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

January 12th, 2007, 12:01 PM
|
|
Wrox Author
Points: 13,210, Level: 49 |
|
|
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,102
Thanks: 1
Thanked 55 Times in 55 Posts
|
|
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
|

January 13th, 2007, 04:47 AM
|
|
Registered User
|
|
Join Date: Jan 2007
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

January 13th, 2007, 11:43 AM
|
|
Friend of Wrox
|
|
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |