|
Subject:
|
Text Files
|
|
Posted By:
|
Jane27
|
Post Date:
|
1/8/2007 4:49:02 AM
|
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
|
|
Reply By:
|
Jane27
|
Reply Date:
|
1/9/2007 3:33:13 AM
|
No gurus?
:-(
|
|
Reply By:
|
c010depunkk
|
Reply Date:
|
1/9/2007 10:14:19 AM
|
What kind of help do you want? A finished app? Or do you have specific questions?
|
|
Reply By:
|
woodyz
|
Reply Date:
|
1/9/2007 11:45:54 AM
|
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
|
|
Reply By:
|
DriveU
|
Reply Date:
|
1/12/2007 4:24:32 AM
|
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
|
|
Reply By:
|
woodyz
|
Reply Date:
|
1/12/2007 10:57:20 AM
|
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
|
|
Reply By:
|
dparsons
|
Reply Date:
|
1/12/2007 12:01:19 PM
|
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
|
|
Reply By:
|
DriveU
|
Reply Date:
|
1/13/2007 4:47:47 AM
|
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.
|
|
Reply By:
|
woodyz
|
Reply Date:
|
1/13/2007 11:43:58 AM
|
quote: Originally posted by DriveU
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
|