Re: [Interest] equivalent of python glob

2019-08-27 Thread Florian Bruhin
On Mon, Aug 26, 2019 at 11:59:00PM +, Hamish Moffatt wrote:
> I think it's a shame there isn't something simpler built in to C++ or Qt
> though.

There's std::filesystem::path::append in C++17:
https://en.cppreference.com/w/cpp/filesystem/path/append

Florian

-- 
https://www.qutebrowser.org | m...@the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
 I love long mails! | https://email.is-not-s.ms/


signature.asc
Description: PGP signature
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] equivalent of python glob

2019-08-26 Thread Jérôme Godbout
I always use '/' for my path, I use to native path only when doing command or 
when needed. I also have toWindowsPath toUnixPath functions when doing cross 
platform request (non native call). The cleanPath() could be useful indeed, but 
if i remeber well I had some special edge case I wanted to cover. Anyway my 
unit test seem to indicate this work properly. If you come with a better 
solution, I could try it, I did not spend too much time on this.


From: Interest  on behalf of Hamish Moffatt 

Sent: Monday, August 26, 2019 7:59 PM
To: interest@qt-project.org 
Subject: Re: [Interest] equivalent of python glob

On 27/8/19 12:33 am, Jérôme Godbout wrote:
> This is what I did for pathJoin
>
> const QString SEPARATOR("/");
> QString FileSystemUtil::pathJoin(const QStringList& paths)


Thanks. You could do that simpler with QDir::cleanPath() and
QDir::toNativeSeparators() I think (and not have to hardcode the separator).


I got my glob working with a mix of QDir, QFileInfo and QDirIterator. I
think it's a shame there isn't something simpler built in to C++ or Qt
though.


Hamish

___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] equivalent of python glob

2019-08-26 Thread Hamish Moffatt

On 27/8/19 12:33 am, Jérôme Godbout wrote:

This is what I did for pathJoin

const QString SEPARATOR("/");
QString FileSystemUtil::pathJoin(const QStringList& paths)



Thanks. You could do that simpler with QDir::cleanPath() and 
QDir::toNativeSeparators() I think (and not have to hardcode the separator).



I got my glob working with a mix of QDir, QFileInfo and QDirIterator. I 
think it's a shame there isn't something simpler built in to C++ or Qt 
though.



Hamish

___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] equivalent of python glob

2019-08-26 Thread Jérôme Godbout
This is what I did for pathJoin

const QString SEPARATOR("/");
QString FileSystemUtil::pathJoin(const QStringList& paths)
{
QString rv;
for(const QString& s : paths)
{
if(!rv.isEmpty() && !rv.endsWith(SEPARATOR))
{
rv += SEPARATOR;
}
if(!rv.isEmpty() && s.startsWith(SEPARATOR))
{
rv += s.right(s.size() - SEPARATOR.size());
}
else
{
rv += s;
}
}
return rv;
}

-Original Message-
From: Interest  On Behalf Of Thiago Macieira
Sent: August 26, 2019 1:37 AM
To: interest@qt-project.org
Subject: Re: [Interest] equivalent of python glob

On Sunday, 25 August 2019 16:34:03 PDT Hamish Moffatt wrote:
> On a related note, where is the equivalent of os.path.join()?

String concatenation. You don't need a function to do it for you.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel System Software Products



___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest
___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] equivalent of python glob

2019-08-25 Thread Thiago Macieira
On Sunday, 25 August 2019 16:34:03 PDT Hamish Moffatt wrote:
> On a related note, where is the equivalent of os.path.join()?

String concatenation. You don't need a function to do it for you.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel System Software Products



___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] equivalent of python glob

2019-08-25 Thread Hamish Moffatt

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

___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] equivalent of python glob

2019-08-23 Thread Bob Hood

On 8/23/2019 9:03 AM, Thiago Macieira wrote:

On Friday, 23 August 2019 07:38:56 PDT Bob Hood wrote:

e.g., QDirIterator iter(base_folder, QStringList() << "*.*", QDir::Files,
QDirIterator::Subdirectories);

"*.*" is "all files containing a dot" (and not in the first character) and the
vast majority of files in /usr/bin don't.


Yeah, sorry, that was from Windows code.

___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] equivalent of python glob

2019-08-23 Thread Thiago Macieira
On Friday, 23 August 2019 07:38:56 PDT Bob Hood wrote:
> e.g., QDirIterator iter(base_folder, QStringList() << "*.*", QDir::Files,
> QDirIterator::Subdirectories);

"*.*" is "all files containing a dot" (and not in the first character) and the 
vast majority of files in /usr/bin don't.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel System Software Products



___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


Re: [Interest] equivalent of python glob

2019-08-23 Thread Bob Hood

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);

___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest


[Interest] equivalent of python glob

2019-08-23 Thread Hamish Moffatt

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.



Does anyone have a recipe?



Thanks

Hamish


___
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest