<?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[[Solved] Howto get the path part of a filename?]]></title><description><![CDATA[<p dir="auto">I have a (relative) filename for a file that doesn't yet exist.</p>
<p dir="auto">Before I can create it, I have to make sure all the parent directories exist. QDir::mkpath should do that for me.</p>
<p dir="auto">However, I cannot simply hand over the filename to mkpath. Instead, I have to hand over the path part of the filename, e.g. for 'home/test/mytest.png' the path part would be 'home/test'</p>
<p dir="auto">Yet, I haven't found any method in QDir, QFile or QFileInfo that would return the path part from a either relative or absolute filename. Nor have I found a function that would allow me to remove the last level from a path/filename. Of course, I can resort to string manipulation, but I feel there should be something more path-aware doing that.</p>
<p dir="auto">Have I missed something?</p>
<p dir="auto">(Qt 4.8)</p>
]]></description><link>https://forum.qt.io/topic/22797/solved-howto-get-the-path-part-of-a-filename</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 10:53:19 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/22797.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 03 Jan 2013 16:18:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Solved] Howto get the path part of a filename? on Thu, 03 Jan 2013 16:55:34 GMT]]></title><description><![CDATA[<p dir="auto">Well according to the doc cannonicalPath() indeed returns empty string if the file doesn't exist but you should be fine with absolutePath()</p>
]]></description><link>https://forum.qt.io/post/161537</link><guid isPermaLink="true">https://forum.qt.io/post/161537</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Thu, 03 Jan 2013 16:55:34 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Howto get the path part of a filename? on Thu, 03 Jan 2013 16:52:57 GMT]]></title><description><![CDATA[<p dir="auto">For a non-existing file?</p>
<p dir="auto">Edit: I was fooled into thinking that QFileInfo would require the file to exist.</p>
]]></description><link>https://forum.qt.io/post/161539</link><guid isPermaLink="true">https://forum.qt.io/post/161539</guid><dc:creator><![CDATA[Asperamanca]]></dc:creator><pubDate>Thu, 03 Jan 2013 16:52:57 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Howto get the path part of a filename? on Thu, 03 Jan 2013 16:29:00 GMT]]></title><description><![CDATA[<p dir="auto">You missed QFileInfo::absolutePath() and QFileInfo::canonicalPath()</p>
]]></description><link>https://forum.qt.io/post/161535</link><guid isPermaLink="true">https://forum.qt.io/post/161535</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Thu, 03 Jan 2013 16:29:00 GMT</pubDate></item></channel></rss>