P
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
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
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
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