473,320 Members | 2,020 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,320 software developers and data experts.

ifstream and format issues

Pat
Here is my problem that I am having with a current project. I went and
backed up all my hard drives to DVD's. After backing up the drives, I
used a batch file to get all the file names from the disk to a text file
for future reference. I now have over 60 huge text files and would like
to place the information into either a database or an excel document.

I would like to read in from a text file and output the text file to an
excel .cvs file or insert statements for an .sql file. The text files
are in a strange format and here is an example:

12/27/2005..12:34.AM....<DIR>..........Mandrakelinux
07/07/2005..03:05.AM.......726,444,032.Mandrakelinux.10. 1.iso
07/07/2005..03:05.AM.......728,047,616.Mandrakelinux.10. 1.iso
( The '.' are whitespaces and all the files are similar to this )

I have the output finished for either format, but getting the correct
format read in is another beast.

//Yes I know Formadder is spelled wrong I just don't like the term
//format when using a windows machine. HA HA.
void Formadder::getData()
{
string newDate; ////
string newTime; // Values for local storage
string newDir; // to put into a vector of
string newFile; // undetermined size.
string newApp; ////

counter = 0; // Used for the application number later.

// Just asking the user for the file name
cout << "Please enter a file name to open: ";
cin >> userInput;
cout << "\n";

//Opening the file and checking to see if the
//file is there.
ifstream inFile;
inFile.open( userInput.c_str() );
if( inFile.fail() )
{
throw( "Could not locate or open file." );
}

//The loop is for getting the contents of the file and
//placing the contents into a vector.
while( !inFile.eof() )
{
//Date Time Dir Size FileName
inFile >> ws >> newDate >> ws >> newTime
ws >> newDir >> ws >> newFile
ws >> newApp;


date.push_back( newDate );
time.push_back( newTime );
directory.push_back( newDir );
fileSize.push_back( newFile );
appName.push_back( newApp );
counter += 1;
}
inFile.close(); //Closing file
}// End function getData

The problem is dealing with the output and whitespaces. ifsteam appears,
and according to several sources, to look for whitespaces or tabs as new
items. This throws off the format that I am trying to achieve. Here is
an example format:

Please enter a file name to open: test.txt

Please enter the disk number: 23

23 1 12/23/2005 01:15 AM <DIR> alg
23 2 12/23/2005 01:15 AM <DIR> ARCADE
23 3 12/23/2005 01:15 AM <DIR> Backup
23 4 12/23/2005 01:17 AM <DIR> Civ4
23 5 12/23/2005 01:17 AM <DIR> CloneCD
23 6 v5.0.0.0 Final Incl 12/23/2005 01:18
23 7 AM <DIR> CombatFS 12/23/2005 10:36
23 8 AM <DIR> Conexant_Drivers 12/23/2005 01:18
23 9 AM <DIR> EBooks 12/23/2005 10:36
I hope that someone can help me to deal with the whitespaces. I have
managed to eliminate the starting whitespaces, but not the ones within
the time and file name.
This is the format I would like to get:
DiskNumber AppNumber Date Time Directory FileSize AppName

Thank you,
Patrick Conlon
Dec 29 '05 #1
2 2921
"Pat" <pa***@cox.net> wrote in message
news:yvMsf.35799$Mi5.12465@dukeread07...
Here is my problem that I am having with a current project. I went and
backed up all my hard drives to DVD's. After backing up the drives, I used
a batch file to get all the file names from the disk to a text file for
future reference. I now have over 60 huge text files and would like to
place the information into either a database or an excel document.

I would like to read in from a text file and output the text file to an
excel .cvs file or insert statements for an .sql file. The text files are
in a strange format and here is an example:

12/27/2005..12:34.AM....<DIR>..........Mandrakelinux
07/07/2005..03:05.AM.......726,444,032.Mandrakelinux.10. 1.iso
07/07/2005..03:05.AM.......728,047,616.Mandrakelinux.10. 1.iso
( The '.' are whitespaces and all the files are similar to this )

I have the output finished for either format, but getting the correct
format read in is another beast.

//Yes I know Formadder is spelled wrong I just don't like the term
//format when using a windows machine. HA HA.
void Formadder::getData()
{
string newDate; ////
string newTime; // Values for local storage
string newDir; // to put into a vector of
string newFile; // undetermined size.
string newApp; ////

counter = 0; // Used for the application number later.

// Just asking the user for the file name
cout << "Please enter a file name to open: ";
cin >> userInput;
cout << "\n";

//Opening the file and checking to see if the
//file is there.
ifstream inFile;
inFile.open( userInput.c_str() );
if( inFile.fail() )
{
throw( "Could not locate or open file." );
}

//The loop is for getting the contents of the file and
//placing the contents into a vector.
while( !inFile.eof() )
{
//Date Time Dir Size FileName
inFile >> ws >> newDate >> ws >> newTime
>> ws >> newDir >> ws >> newFile
>> ws >> newApp;


date.push_back( newDate );
time.push_back( newTime );
directory.push_back( newDir );
fileSize.push_back( newFile );
appName.push_back( newApp );
counter += 1;
}
inFile.close(); //Closing file
}// End function getData

The problem is dealing with the output and whitespaces. ifsteam appears,
and according to several sources, to look for whitespaces or tabs as new
items. This throws off the format that I am trying to achieve. Here is an
example format:

Please enter a file name to open: test.txt

Please enter the disk number: 23

23 1 12/23/2005 01:15 AM <DIR> alg
23 2 12/23/2005 01:15 AM <DIR> ARCADE
23 3 12/23/2005 01:15 AM <DIR> Backup
23 4 12/23/2005 01:17 AM <DIR> Civ4
23 5 12/23/2005 01:17 AM <DIR> CloneCD
23 6 v5.0.0.0 Final Incl 12/23/2005 01:18
23 7 AM <DIR> CombatFS 12/23/2005 10:36
23 8 AM <DIR> Conexant_Drivers 12/23/2005 01:18
23 9 AM <DIR> EBooks 12/23/2005 10:36
I hope that someone can help me to deal with the whitespaces. I have
managed to eliminate the starting whitespaces, but not the ones within the
time and file name.
This is the format I would like to get:
DiskNumber AppNumber Date Time Directory FileSize AppName

Thank you,
Patrick Conlon


Consider reading an entire line at a time then parsing it. Your problem
seems to be in spaces in the file name, but since it's at the end of the
line, you should just take everything from the filename to the end of the
line as the filename.

Using >> you're not going to be able to do this I don't think, unless you,
somehow, check for \n which I'm not even sure >> can do for you.
Dec 29 '05 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Pat wrote:
Here is my problem that I am having with a current project. I went and
backed up all my hard drives to DVD's. After backing up the drives, I
used a batch file to get all the file names from the disk to a text file
for future reference. I now have over 60 huge text files and would like
to place the information into either a database or an excel document.

I would like to read in from a text file and output the text file to an
excel .cvs file or insert statements for an .sql file. The text files
are in a strange format and here is an example:

12/27/2005..12:34.AM....<DIR>..........Mandrakelinux
07/07/2005..03:05.AM.......726,444,032.Mandrakelinux.10. 1.iso
07/07/2005..03:05.AM.......728,047,616.Mandrakelinux.10. 1.iso
( The '.' are whitespaces and all the files are similar to this )

I have the output finished for either format, but getting the correct
format read in is another beast.

//Yes I know Formadder is spelled wrong I just don't like the term
//format when using a windows machine. HA HA.
void Formadder::getData()
{
string newDate; ////
string newTime; // Values for local storage
string newDir; // to put into a vector of
string newFile; // undetermined size.
string newApp; ////

counter = 0; // Used for the application number later.

// Just asking the user for the file name
cout << "Please enter a file name to open: ";
cin >> userInput;
cout << "\n";

//Opening the file and checking to see if the
//file is there.
ifstream inFile;
inFile.open( userInput.c_str() );
if( inFile.fail() )
{
throw( "Could not locate or open file." );
}

//The loop is for getting the contents of the file and
//placing the contents into a vector.
while( !inFile.eof() ) Typically, the extractor mechanisms for formatted extraction are not
used on the stream. Instead, you often see something like the following:

while (infile.getline(line, BUFSIZE, '\n')) {

Then for the parsing operation, you might try and cleanup the input with
a mutating function such as remove to get rid of tabs. {
//Date Time Dir Size FileName
inFile >> ws >> newDate >> ws >> newTime
>> ws >> newDir >> ws >> newFile
>> ws >> newApp;


date.push_back( newDate );
time.push_back( newTime );
directory.push_back( newDir );
fileSize.push_back( newFile );
appName.push_back( newApp );
counter += 1;
}
inFile.close(); //Closing file
}// End function getData

The problem is dealing with the output and whitespaces. ifsteam appears,
and according to several sources, to look for whitespaces or tabs as new
items. This throws off the format that I am trying to achieve. Here is
an example format:

Please enter a file name to open: test.txt

Please enter the disk number: 23

23 1 12/23/2005 01:15 AM <DIR> alg
23 2 12/23/2005 01:15 AM <DIR> ARCADE
23 3 12/23/2005 01:15 AM <DIR> Backup
23 4 12/23/2005 01:17 AM <DIR> Civ4
23 5 12/23/2005 01:17 AM <DIR> CloneCD
23 6 v5.0.0.0 Final Incl 12/23/2005 01:18
23 7 AM <DIR> CombatFS 12/23/2005 10:36
23 8 AM <DIR> Conexant_Drivers 12/23/2005 01:18
23 9 AM <DIR> EBooks 12/23/2005 10:36
I hope that someone can help me to deal with the whitespaces. I have
managed to eliminate the starting whitespaces, but not the ones within
the time and file name.
This is the format I would like to get:
DiskNumber AppNumber Date Time Directory FileSize AppName

Thank you,
Patrick Conlon


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFDtXfVpxCQXwV2bJARAn9EAJ9XGY3ifpnrCiCF0n5iVN UcClDhmwCfQ/wI
RO5uR2leDEWa4vKNpuX+uos=
=aBD+
-----END PGP SIGNATURE-----
Dec 30 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave Johnston | last post by:
Hi, I'm currently trying to create a wrapper that uses C functions but behaves like ifstream (from fstream.h) - this is because the platform I'm using (WinCE) doesn't support streams and this is...
6
by: Ram Laxman | last post by:
Iam new bie to C++ programming.. I want to write a program which will read the Comma separated values(CSV) file column wise. For example: In a.txt: "TicketNumber","Phone","CarNumber"...
4
by: hall | last post by:
Hi. I ran across a bug in one of my problems and after spending some time tracking it down i found that the problem arose in a piece of code that essentially did this: ----------- ifstream...
10
by: sam | last post by:
Hi, Can anyone tell me how to print a file name from ifstream? the following cout code does not print the filename I created with ifstream preivous: ifstream is; is.open ("text.txt");
1
by: James Lehman | last post by:
Hello. I want to write a program that reads AutoCAD shape (font) files. They are written with the convention that hexadecimal values have a leading zero and decimal values do not. All numbers...
4
by: marathoner | last post by:
I tried your advice, and replaced "ifstream" with "std::ifstream". I also replaced instances of "ofstream" with "std::ofstream". Those syntax errors were resolved. When I added "std" to the...
7
by: Boltar | last post by:
Hi I'm using ifstream (which I hardly ever use) to read an ascii text file (containing numbers delimited by newlines) in a loop using something like: ifstream infile("filename") int value; ...
11
by: adramolek | last post by:
So... I'm trying to get used to using C++ ifstream (or ofstream) instead of stdio (although I'm having second thoughts). Anyways, I want to be able to display a meaningful error message if ifstream...
0
by: James Kanze | last post by:
On 11 avr, 17:44, "mc" <mc_r...@yahoo.comwrote: OK. If the actual format is well documented, that's half the battle won already. Note, however, that reading a float as an int is still very...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.