Question

I am making a small program to help with file reading.

i have a for loop to take in commands from the command line:

 for (i = 1; argc > i; i++)
            {
                QString path = QDir::currentPath()+ "/" + QString(argv[i]);
                QDir dir(path);
                fileSearch(dir);
            }

from there I call another method where I look into each file/foler and get the size and whether its a file or folder.

void fileSearch(QDir dir)
{
        foreach(QFileInfo info, dir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files | QDir::AllDirs ))
            {
                if (info.isFile())
                {
                    qDebug() << info.path() << "is a file! its size is:" << info.size() << endl;
                }
                if (info.isDir())
                {
                    qDebug() << info.path() << "is a directory! its size is:" << info.size() << endl;
                    fileSearch(info.filePath());
                }
            }

instead of reading the whole entire path, I want it to read just the relative path. So instead of it reading:

home/john/desktop/project/currentproject/checkdirectory is a directory! its size is: 4096
home/john/desktop/project/currentproject/checkdirectory/test.txt is a file! its size is: 4

I want it to read:

checkdirectory/ is a directory! its size is: 4096
checkdirectory/test.txt is a file! its size is: 4
Was it helpful?

Solution

QString QDir::relativeFilePath(const QString & fileName);

should return the relative file path.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top