[Interest] equivalent of python glob

Hamish Moffatt hamish at risingsoftware.com
Mon Aug 26 01:34:03 CEST 2019


On 24/8/19 12:38 am, Bob Hood wrote:
> On 8/23/2019 12:46 AM, Hamish Moffatt wrote:
>> Hi,
>>
>> In Python one can write the expression: glob.glob("/usr/bin/*") and 
>> get a list of such files. I am looking for something similar in Qt 
>> (in C++).
>>
>> I have look at QDir::entryList() and entryInfoList(), but it seems I 
>> would have to extract the path first and provide it to QDir. I can't 
>> use QDir('/').entryList({ "/usr/bin/*" }), as it returns nothing.
>
> Look at QDirIterator.
>
> e.g., QDirIterator iter(base_folder, QStringList() << "*.*", 
> QDir::Files, QDirIterator::Subdirectories);


But I am looking for a method where I don't have to separate the base 
folder. I want to accept user input like "/usr/bin/*" and list those 
files, but I haven't found a way to provide this path directly to Qt. It 
looks like I need to split off the path first.

QDirIterator behaves the same as QDir, which I tried originally as I 
wrote above. Here it is tested in Python:


 >>> from PyQt5 import QtCore
 >>> di=QtCore.QDirIterator("/", ["/usr/bin/*"])
 >>>
 >>> di.next()
''


On a related note, where is the equivalent of os.path.join()?


thanks

Hamish




More information about the Interest mailing list