Pietro
Pietro

Reputation: 13164

How to get a complete path from one with wildcards?

I have a path like:

C:\path\to\my*file\

and I would like to get the corresponding full path (if it exists):

C:\path\to\my1file\

I tried with this Qt code, but the result is the same path I had at the beginning:

QStringList filters;
filters << "C:/path/to/my*file/";

QDir dir;
dir.setNameFilters(filters);

QStringList dirs = dir.entryList(filters);

_path = dirs.at(0);     // get the first path only

Shouldn't I get all the files/directories that get through the filter?
Why is _path equal to "C:/path/to/my*file/"?

Is it possible to do the same thing with C++98/STL only? (In this project I cannot use Boost/C++11).

Upvotes: 0

Views: 2874

Answers (2)

asclepix
asclepix

Reputation: 8061

Use filters to filter files/folders, and set the path in QDir object:

QStringList filters;
filters << "my*file";

QDir dir("C:/path/to/");
QStringList dirs = dir.entryList(filters);

if (dirs.size() > 0)
{
    qDebug() << dirs.at(0);
}

Upvotes: 4

brian beuning
brian beuning

Reputation: 2862

Expanding file names is called globbing. On Windows the functions FindFirstFile() / FindNextFile() do globbing.

Upvotes: 0

Related Questions