Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Howto get the path part of a filename?
Forum Updated to NodeBB v4.3 + New Features

[Solved] Howto get the path part of a filename?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #1

    I have a (relative) filename for a file that doesn't yet exist.

    Before I can create it, I have to make sure all the parent directories exist. QDir::mkpath should do that for me.

    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'

    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.

    Have I missed something?

    (Qt 4.8)

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You missed QFileInfo::absolutePath() and QFileInfo::canonicalPath()

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        For a non-existing file?

        Edit: I was fooled into thinking that QFileInfo would require the file to exist.

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Well according to the doc cannonicalPath() indeed returns empty string if the file doesn't exist but you should be fine with absolutePath()

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved