Important: Please read the Qt Code of Conduct -

Synchronizing dir in windows

  • Hi,

    Currently i have made a programme in QT, In which the programme is able to read all xml files from given dir and make a new copy of it.

    This is working perfect.

    Now what I want is not to just read only xml files but all files with different extensions present in given folder and write them. So the extension can be .exe .png .ico .jpg probably all extension supported by windows. If not all then possibly majority of them.

    Please help me

    QStringList path = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
        QDir dir(path.first()+"/test");
        QStringList xmlfiles = dir.entryList(QStringList() << "*.xml" << "*.XML",QDir::Files);
        foreach(QString nfile, xmlfiles) {
        QDomDocument doc;
        QFile file(dir.path() +"/" + nfile);
        qDebug() << file.exists();
        QString x = doc.toString();
        QDomDocument doc1;
        QFile file1(dir.path() +"/" + "new" + nfile);;

  • Qt Champions 2017

    Currently you are passing only xml filter. Add additional filters.
    Create filters like follows and pass the filters to entry list.
    myfilters << ".xml" << ".XML" << ".jpeg"<<".bmp

  • @dheerendra thank you for the reply may i know how many types of filters are supported by qt.

  • @Mandeep-Chaudhary

    Since it's a QStringList you can add an almost infinite number of extensions to your filter. Only limited to the size of available memory for your variable. I guess it's somewhere around 2^32, so even if it's a lot less, you could probably store every single existing file extension in this list :-)

    But if you want ALL file extensions, why don't you use "all files" (= no file extension filter)?

  • Instead of passing QStringList as parameter u can just use the below function to read all the files with any extension.

    QStringList xmlfiles= dir.entrylist(QDir::Files,QDir::NoSort);

    or else you can add whatever the extensions you want to the QStringList nameFilters.

Log in to reply