PDA

View Full Version : QDir Path problem



ToddAtWSU
7th August 2008, 18:49
I have a program that attempts to save a file in a predetermined directory if it exists, otherwise the user is prompted where to save the file to.

The file is of a very specific naimg convention of #####XX###X.txt where #=number and X=letter.

There is also a corresponding directory located at "/someDir/anotherDir/aThirdDir/#####XX###X/manySubDirs". The #s and Xs in the filename are the same as in the directory so they match 100%.

Now sometimes the directory may be listed as aThirdDir/#####XX###X_XXX where the creator of the directory puts their initials at the end of the directory listing. I am trying to save the file in "/someDir/anotherDir/aThirdDir/#####XX###X_XXX/oneSubDir/". So I get the environment variable that holds "/someDir/anotherDir/aThirdDir/" and then append the #####XX###X to this directory listing. What I want to do then is append a "*" after the common name so if the _XXX part is there it will know to include this in the directory string. You can "cd" in this manner in a unix terminal window but it appears when I attempt to use the


QDir::isAbsolutePath( QString( "/someDir/anotherDir/aThirdDir/#####XX###X*/oneSubDir" ) );

It says the directory doesn't exist. Is there a way to get the QDir to know the * means a wildcard character and not the actual * character? Sorry for the long-winded explanation, but I thought a background on my problem could help find a solution. Thanks!

Arsenic
8th August 2008, 01:44
You will have to code your own little "*" wildcard.
Which isn't really too hard.
Loop through all the Dirs, and pick the first one that matches closely enough.

jpn
8th August 2008, 18:29
There is QAbstractFileEngineHandler which can do exactly what you want:


#include <QtGui>

class WildcardEngineHandler : public QAbstractFileEngineHandler
{
public:
QAbstractFileEngine* create(const QString& fileName) const;
};

QAbstractFileEngine* WildcardEngineHandler::create(const QString& fileName) const
{
if (fileName matches the pattern)
{
// fill in place holders in the name
return new QFSFileEngine(actualFileName);
}
return 0;
}

int main(int argc, char **argv)
{
QApplication app(argc, argv);
WildcardEngineHandler engine;

...

return app.exec();
}

ToddAtWSU
21st August 2008, 13:15
I will give this a try. Was out of town the past 2 weeks and just now got a chance to look back into this. Thanks!