PDA

View Full Version : QDir: dealing with folders with special characters



papillon
12th October 2011, 00:24
I'm doing a recursive scan of a folder, and noticed that if a folder name is, for example,

!myfolder

QDir will replace the "!" with "..", and next loop will try to get to the parent folder, instead of continuing the recursion.

How are we supposed to deal with folder containing special characters? Thanks

slqh
12th October 2011, 05:53
As i'm still a noob in Qt related things I cant give you a pure Qt solution.
But if you are already using boost maybe you can use the filesystem library that uses unicode to manage paths, that should get you going even with non ASCII folder names ( for example latin characters like ñ ).

LInk -> http://www.boost.org/doc/libs/1_47_0/libs/filesystem/v3/doc/tutorial.html

papillon
12th October 2011, 20:52
As i'm still a noob in Qt related things I cant give you a pure Qt solution.
But if you are already using boost maybe you can use the filesystem library that uses unicode to manage paths, that should get you going even with non ASCII folder names ( for example latin characters like ñ ).

LInk -> http://www.boost.org/doc/libs/1_47_0/libs/filesystem/v3/doc/tutorial.html

Thanks for that link, will study this...

ChrisW67
13th October 2011, 01:07
QDir will replace the "!" with "..", and next loop will try to get to the parent folder, instead of continuing the recursion.
Please post a minimal, complete example that reproduces this behaviour.

It clearly doesn't do anything like that here:


#include <QtCore>
#include <QDebug>

int main(int argc, char** argv)
{
QCoreApplication app(argc, argv);

QDir dir;
dir.cd("a");
qDebug() << "Content of a" << dir.entryList();
dir.cd("!b");
qDebug() << "Content of a/!b" << dir.entryList();

return 0;
}

when run:


$ find a
1949745 4 drwxr-xr-x 3 chrisw users 4096 Oct 13 10:01 a
1949748 0 -rw-r--r-- 1 chrisw users 0 Oct 13 10:01 a/afile
1949746 4 drwxr-xr-x 2 chrisw users 4096 Oct 13 10:01 a/!b
1949747 0 -rw-r--r-- 1 chrisw users 0 Oct 13 10:01 a/!b/bfile
$ ./test
Content of a ("!b", ".", "..", "afile")
Content of a/!b (".", "..", "bfile")