All about programming in GNU/LINUX

Qt C++ code for GNU/LINUX to print the directory content of the Home folder and one level recursive traversal

#include <QtCore/QCoreApplication>
#include<QDebug>
#include<QDir>
#include<QFileInfo>
#include<QString>
#include<unistd.h>
int main(int argc, char *argv[])
{

    QCoreApplication a(argc, argv);
    char homepath[100]="/home/";
    char *usrname=getlogin();
    strcat(homepath,usrname);
    QString linuxpath(homepath);
    QDir dir;
    QString output;
    qDebug()<< dir.exists(linuxpath);
    foreach(QFileInfo path,dir.drives())
    {
        qDebug() <<  path.absoluteFilePath();

    }
    QDir abpath(linuxpath);
    QDir abcpath;
    foreach(QFileInfo path2,abpath.entryInfoList())
    {
        qDebug()<< path2.absoluteFilePath();
        output=path2.absoluteFilePath();
        abcpath.setPath(output);
        foreach(QFileInfo path3,abcpath.entryInfoList())
        {
            qDebug()<<"\t"<< path3.absoluteFilePath();


        }
    }

    return a.exec();
}

Steps for execution

1.Create an QT console project and execute the code
2.Run the executable from the terminal after successfull compilation

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s