Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8676265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:09:02+00:00 2026-06-12T20:09:02+00:00

I am trying to walk a directory recursively and modify its contents,that modification should

  • 0

I am trying to walk a directory recursively and modify its contents,that modification should be done for all files and files of sub directories.

void EncryptMountedFolder(QString DirPath)
{
        QStringList listFile;
        QStringList listDir;
        int r=0;
    if(WalkDir(DirPath,listFile,listDir))
     {

        foreach (QString filePath, listFile)
        {
        //modif of file with filePath as path
        }

        foreach(QString subdirPath, listDir)
        {
            EncryptMountedFolder(subdirPath);
        }

      }
      else qDebug()<<"can not find "<<DirPath<<"or it is not folder path ";

}

WalkDir function:

bool WalkDir(QString DirPath, QStringList &FList, QStringList &DList)
{
    QString p=QDir::fromNativeSeparators(DirPath);
    QDir dir( p );
    if(dir.exists())
    {           
          dir.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks );
          const QFileInfoList fileinfolist = dir.entryInfoList();

          foreach(const QFileInfo& fi,fileinfolist)
              if(fi.baseName() != "")
              {
                if( fi.isDir() && fi.isReadable() )
                 DList=DList << fi.absoluteFilePath() ;
                 else
                    FList= FList<< fi.absoluteFilePath();
              }              
        return true;
    }
    else
        {    qDebug()<<"not valid dir path or doesn't exist"<<DirPath ;
             return false;
         }    
}

Files under all sub directories were modified as I want, but it crashes and I get: Critical error detected c0000374 that point me to qlist.h in Q_OUTOFLINE_TEMPLATE void QList<T>::free(QListData::Data *data) function line qFree(data);

Can anyone find out what I miss?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:09:03+00:00Added an answer on June 12, 2026 at 8:09 pm

    As per my last comment, this is my suggestion to simplify the walking function (based on this):

    void walk( const QString& dirname )
    {
      QDir dir( dirname );
      dir.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks );
    
      const QFileInfoList fileinfolist = dir.entryInfoList();
      foreach( const QFileInfo& fi,fileinfolist ) {
        if( fi.baseName() == "." || fi.baseName() == ".."  || fi.baseName() == "" ) {
          continue;
        }
        if( fi.isDir() && fi.isReadable() ) {
          // This is the conditional for recursion
          walk( fi.absoluteFilePath() );
        }
        else {
          // This is where you might call your encrypting function
          qDebug() << "Encrypting file: " << fi.absoluteFilePath();
          encrypt( fi.absoluteFilePath() );
        }
      }
    }
    

    You can also make it more generic by passing the encrypting function as a callback to walk(). So that you can reuse it for other types of processing you might need to apply.

    Also if you’re keen on testing your code, you might notice that my previous suggestion, is not unit-testable: for a method to be easily testable, it should have non-dependent input and output, and your test would check the output against the expected value.

    So here is a version that returns the list of all files collected from the given directory tree:

    QStringList walk( const QString& dirname )
    {
      QDir dir( dirname );
      dir.setFilter( QDir::Dirs | QDir::Files | QDir::NoSymLinks );
    
      const QFileInfoList fileinfolist = dir.entryInfoList();
      QStringList collectedFileList;
      foreach( const QFileInfo& fi,fileinfolist ) {
    
        if( fi.baseName() == "." || fi.baseName() == ".."  || fi.baseName() == "" ) {
          continue;
        }
    
        if( fi.isDir() && fi.isReadable() ) {
          collectedFileList << walk( fi.absoluteFilePath() );
        }
        else {
          collectedFileList << fi.absoluteFilePath();
        }
      }
      return collectedFileList;
    }
    

    And now you can add a third method to loop over the files and encrypt them:

    void encryptDirectoryTree( const QString& dirname )
    {
         QStringList filesInDir = walk( dirname );
         foreach( const QString& filePath, filesInDir ) {
            encrypt( filePath );
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to walk a directory, retrieve all files within that directory ending with
I'm trying to write a function that backs up a directory with files of
I'm trying to make a script to list all directories, subdirectories, and files in
Trying to enumerate all files in a certain directory (like 'find .' in Linux,
I am trying to write code that will fetch the files in a directory
I am trying to list directories and files (recursivley) in a directory with python:
Trying to implement LoaderManager + CursorLoader. In onFinish method adapter should swap its cursor
I'm trying to delete old SVN files from directory tree. shutil.rmtree and os.unlink raise
Python newb...beware! I am trying to recursively ftp some files. In the script below,
I am trying to recursively loop through a series of directories (about 3 levels

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.