Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Synchronizing dir in windows
Forum Updated to NodeBB v4.3 + New Features

Synchronizing dir in windows

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 324 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mandeep.Chaudhary
    wrote on last edited by Mandeep.Chaudhary
    #1

    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();
        doc.setContent(&file);
        file.close();
    
        QString x = doc.toString();
    
    
        QDomDocument doc1;
        doc1.setContent(x);
        QFile file1(dir.path() +"/" + "new" + nfile);
        file1.open(QFile::WriteOnly);
        file1.write(doc1.toByteArray(1));
        file1.close();
        }
    
    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      M 1 Reply Last reply
      2
      • dheerendraD dheerendra

        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

        M Offline
        M Offline
        Mandeep.Chaudhary
        wrote on last edited by
        #3

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

        Pl45m4P 1 Reply Last reply
        0
        • M Mandeep.Chaudhary

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

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by Pl45m4
          #4

          @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 :-)

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


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          3
          • Ashok KumarA Offline
            Ashok KumarA Offline
            Ashok Kumar
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            3

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved