<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Can QDir filter by filename length ?]]></title><description><![CDATA[<p dir="auto">Custom filter first.</p>
<p dir="auto">void QDir::setFilter(QDir::Filters filters)</p>
]]></description><link>https://forum.qt.io/topic/164499/can-qdir-filter-by-filename-length</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 09:34:36 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/164499.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 30 Mar 2026 09:00:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Can QDir filter by filename length ? on Mon, 30 Mar 2026 09:03:35 GMT]]></title><description><![CDATA[<p dir="auto">No, <code>QDir</code> itself can’t filter files by filename length directly.</p>
<p dir="auto"><code>QDir</code> only supports basic name filters (like wildcards), sorting, and attribute-based filters (files, dirs, hidden, etc.). It doesn’t provide filtering based on properties like string length.</p>
<p dir="auto">The usual way to handle this is to get the file list first and then filter it manually. For example:</p>
<pre><code class="language-cpp">QDir dir("your/path");
QStringList files = dir.entryList(QDir::Files);

QStringList filtered;
for (const QString &amp;file : files) {
    if (file.length() == 10) { // or whatever length you need
        filtered.append(file);
    }
}
</code></pre>
<p dir="auto">If you need more file details, you can also use <code>entryInfoList()</code> and work with <code>QFileInfo</code>.</p>
<p dir="auto">So in short: not built-in, but easy to implement with a simple loop 👍</p>
]]></description><link>https://forum.qt.io/post/837419</link><guid isPermaLink="true">https://forum.qt.io/post/837419</guid><dc:creator><![CDATA[SabarishR]]></dc:creator><pubDate>Mon, 30 Mar 2026 09:03:35 GMT</pubDate></item><item><title><![CDATA[Reply to Can QDir filter by filename length ? on Wed, 01 Apr 2026 06:59:15 GMT]]></title><description><![CDATA[<p dir="auto">You could use <code>QDir::setNameFilters</code> (<a href="https://doc.qt.io/qt-6/qdir.html#setNameFilters" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-6/qdir.html#setNameFilters</a>). The documentation mentions that you can use <code>*</code> and <code>?</code> wildcards. If you don't know this: <code>?</code> filters exactly one character. So, to filter for a specific length, just use that number of question marks as name filter.</p>
]]></description><link>https://forum.qt.io/post/837474</link><guid isPermaLink="true">https://forum.qt.io/post/837474</guid><dc:creator><![CDATA[SimonSchroeder]]></dc:creator><pubDate>Wed, 01 Apr 2026 06:59:15 GMT</pubDate></item><item><title><![CDATA[Reply to Can QDir filter by filename length ? on Mon, 30 Mar 2026 09:03:35 GMT]]></title><description><![CDATA[<p dir="auto">No, <code>QDir</code> itself can’t filter files by filename length directly.</p>
<p dir="auto"><code>QDir</code> only supports basic name filters (like wildcards), sorting, and attribute-based filters (files, dirs, hidden, etc.). It doesn’t provide filtering based on properties like string length.</p>
<p dir="auto">The usual way to handle this is to get the file list first and then filter it manually. For example:</p>
<pre><code class="language-cpp">QDir dir("your/path");
QStringList files = dir.entryList(QDir::Files);

QStringList filtered;
for (const QString &amp;file : files) {
    if (file.length() == 10) { // or whatever length you need
        filtered.append(file);
    }
}
</code></pre>
<p dir="auto">If you need more file details, you can also use <code>entryInfoList()</code> and work with <code>QFileInfo</code>.</p>
<p dir="auto">So in short: not built-in, but easy to implement with a simple loop 👍</p>
]]></description><link>https://forum.qt.io/post/837419</link><guid isPermaLink="true">https://forum.qt.io/post/837419</guid><dc:creator><![CDATA[SabarishR]]></dc:creator><pubDate>Mon, 30 Mar 2026 09:03:35 GMT</pubDate></item></channel></rss>