paip.c++ qt 目录遍历以及文件操作

paip.c++ qt 目录遍历以及文件操作




作者Attilax ,  EMAIL:[email protected] 
来源:attilax的专栏
地址:http://blog.csdn.net/attilax



#include <QMessageBox>
#include <QFileDialog>
#include "helo.h"


//#include <qfile.h>
//#include <qdir.h>
//#include <qfileinfo.h>
//#include<qdiriterator.h>
 #include <QtCore>
//#include <QFileInfoListIterator>
//#include "qfileinfo.h"
//#include <QDirIterator>
//#include <attilaxc9>
//#include <QDirIterator>
#include <qtextstream.h>
//for select  dir and scan pic
void MainWindow::on_pushButton_2_clicked()
{
    /*
    QFileDialog *fileDialog = new QFileDialog(this);
    fileDialog->setWindowTitle(tr("Open Image"));
    fileDialog->setDirectory(".");
    //     fileDialog->setFilter(tr("Image Files(*.jpg *.png)"));
    if(fileDialog->exec() == QDialog::Accepted) {
        QString path = fileDialog->selectedFiles()[0];
        QMessageBox::information(NULL, tr("Path"), tr("You selected ") + path);
    } else {
        //  QMessageBox::information(NULL, tr("Path"), tr("You didn't select any files."));
    }
    */


    QString   path=QFileDialog::getExistingDirectory(NULL, tr("选择文件夹"),"c:\\i",QFileDialog::ShowDirsOnly);
    QDir dir(path);
    if (!dir.exists())
        return ;
    // dir.setFilter(QDir::Dirs|QDir::Files);
    //  dir.setSorting(QDir::DirsFirst);
    //   QFileInfoList list = dir.entryInfoList();
    QFileInfoList list = dir.entryInfoList();




    QDirIterator it(path,QDirIterator::NoIteratorFlags);
    while (it.hasNext()) {
        QString filename=   it.next();
        QString path_ext1=path+"/.";
        QString path_ext2=path+"/..";
        if(filename== path_ext1 || filename== path_ext2)
            continue;
        qDebug() << filename;
        processImg(filename);


    }


    /**/




}






void MainWindow ::output2log(QString filename,QString txt)
{
    QString fileName =filename;


    QFile f( fileName );


    f.open(QIODevice::WriteOnly );


    QTextStream t(&f);


    t <<  txt;


    f.close();
}

你可能感兴趣的:(文件操作)