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. How to open a directory and check this content?
Forum Updated to NodeBB v4.3 + New Features

How to open a directory and check this content?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 3.2k Views 1 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.
  • I Offline
    I Offline
    I-sty
    wrote on last edited by
    #1

    Hi,

    I would like to open a directory and scanning that empty or not.

    @QString directory = QFileDialog::getExistingDirectory(this, tr("Browse folder"), QDir::homePath (), QFileDialog::DontResolveSymlinks);

    if (!QFileInfo(directory).size ())
    {
        ui->sfTextEdit->setText ("The selected folder is empty!");
    }
    else
    {
        ui->sfTextEdit->setText ("The selected folder is not empty!");
    }@
    

    I wrote this script, but didn't work.

    Sorry, for my bad English. My first language is Hungarian.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DKvita
      wrote on last edited by
      #2

      QFileInfo(...).size() works only for files, try QDir(...).count().

      1 Reply Last reply
      0
      • I Offline
        I Offline
        I-sty
        wrote on last edited by
        #3

        I dunno how to :(

        I would like to select a directory and write out the content in a list.
        Example:
        I selected D:/Music/Adele
        And the app will write that:

        Adele - Someone like you -> 5mb
        Adele - somename -> 6mb
        .....

        Sorry, for my bad English. My first language is Hungarian.

        1 Reply Last reply
        0
        • mrdebugM Offline
          mrdebugM Offline
          mrdebug
          wrote on last edited by
          #4

          Look at this function:

          @void QThAnalyze::SideList(QString Path) {
          QVector<FileItem> *QVSideList= new QVector<FileItem>();
          QDir QDPath= QDir(Path);
          QDPath.setSorting(QDir::Name);
          QStringList QSLFiles= QDPath.entryList(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden);
          if (QSLFiles.size()== 0) emit SendEmptyDirs(Side, Path);
          else {
          for (int count= 0; count< QSLFiles.size(); count++) {
          FileItem fileitem;
          fileitem.Path= Path+ QDir::separator();
          if (fileitem.Path.startsWith(InitialPath)) fileitem.Path= fileitem.Path.right(fileitem.Path.length()- InitialPath.length());
          fileitem.File= QSLFiles[count];
          QFileInfo QFIPath(Path+ QDir::separator()+ QSLFiles[count]);
          struct stat FileAttributes;
          stat(QString(Path+ QDir::separator()+ QSLFiles[count]).toStdString().c_str(), &FileAttributes);
          //qDebug() << QString(Path+ QDir::separator()+ QSLFiles[count]).toStdString().c_str(); <<<---------
          if (QFIPath.isDir()) {
          fileitem.IsDirectory= true;
          Directories++;
          QVSideList->append(fileitem);
          if (DoStart) emit SendFiles(Side, Files, Directories, QVSideList);
          QVSideList->clear();
          if (DoStart && QFIPath.isDir() &! QFIPath.isSymLink()) SideList(Path+ QDir::separator()+ QSLFiles[count]);
          } else {
          fileitem.IsDirectory= false;
          fileitem.Size= QFIPath.size();
          Files++;
          fileitem.LastAccess= FileAttributes.st_atime;
          fileitem.LastModified= FileAttributes.st_mtime;
          QVSideList->append(fileitem);
          }
          }
          if (DoStart) emit SendFiles(Side, Files, Directories, QVSideList);
          }
          }@

          How you can see the "QDir QDPath= QDir(Path);" contains the content of directory. "QFileInfo" and "stat" function contain the attributes.
          Look at full source here: "Your text to link here...":http://kde-apps.org/content/show.php/?content=149622
          file qthanalyze.cpp

          Need programmers to hire?
          www.labcsp.com
          www.denisgottardello.it
          GMT+1
          Skype: mrdebug

          1 Reply Last reply
          0

          • Login

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