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
var relativePath = Path. GetRelativePath( @"C:\Program Files\Dummy Folder\MyProgram", @"C:\Program Files\Dummy Folder\MyProgram\Data\datafile1. dat"); In the above example, the relativePath variable is equal to Data\datafile1.
Relative paths make use of two special symbols, a dot (.) and a double-dot (..), which translate into the current directory and the parent directory. Double dots are used for moving up in the hierarchy.
QString QDir::relativeFilePath(const QString & fileName);
should return the relative file path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With