i want to access and read the data of some files i.e 2 or three files from the directory
now i am accessing all the files from the directory
the file is text file
plzzz help
i want to access and read the data of some files i.e 2 or three files from the directory
now i am accessing all the files from the directory
the file is text file
plzzz help
Change your code so you read only the files you are interested in, instead of all of them.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
QString path=QFileDialog::getExistingDirectory();
QDir dir(path);
foreach (QFileInfo fileinfo, dir.entryInfoList(QDir::Files) )
{
QString filename = fileinfo.filePath();
QFile readFile(filename);
if(!readFile.open(QFile::ReadWrite | QFile::Text ) )
{
qDebug("Failed to read file.....");
//return ;
}
i am using foreach for access all the file of the directory
what else i shold use to access the particular 2 or three files
Well, what did you think that would do besides read every file in the directory?i am using foreach for access all the file of the directory
Qt Code:
{ if ( amIInterestedInThisFile( filename ) == true ) { { qDebug("Failed to read file....."); } } }To copy to clipboard, switch view to plain text mode
You're going to have to write the method "bool amIInterestedInThisFile( const QString & fileName )" because only you know which two or three files you want to read.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
IT IS reading all the files one by one i want to read the files with its name i.e when i give the name of files it should read the text of that files only
for e.g if file has starting name same then it should read all the files of the same name files after executing
boolamiInterestedinthisfile is not declared
Then read the files you want, don't list all the file in the dir
Qt Code:
// QString path = QFileDialog::getExistingDirectory(); // QDir dir(path); // foreach (QFileInfo fileinfo, dir.entryInfoList(QDir::Files) ) QList<QString> files { "File1.txt", "File2.txt", "File3.txt" }; { { qDebug("Failed to read file....."); //return ; } }To copy to clipboard, switch view to plain text mode
When you know how to do it then you may do it wrong.
When you don't know how to do it then it is not that you may do it wrong but you may not do it right.
Anupamp (28th February 2017)
Bookmarks