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. Remove the path of a QString file
Forum Updated to NodeBB v4.3 + New Features

Remove the path of a QString file

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 3.5k 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.
  • KonstantinosK Offline
    KonstantinosK Offline
    Konstantinos
    wrote on last edited by Konstantinos
    #1

    Imagine we have QString file. File has directories any time. For example:

    C:/Qt/5.6/mingw49_32/bin/example.xml
    C:/Qt/raining/now/clouds/nature.png
    D:/sun/no_clouds/newworldorder/soon.txt

    Is there a smart way to take the names from this file:

    example.xml
    nature.png
    soon.txt

    or the last two names:

    bin/example.xml
    clouds/nature.png
    newworldorder/soon.txt

    There is the choice .remove.

    But you have to know what you want to remove, for example, file.remove("C:/Qt/5.6/mingw49_32/bin/").

    If you only want to remove all the folder - file names, except the last two ones?

    removefolder(2, file)?

    Thanks in advance.

    kshegunovK 1 Reply Last reply
    0
    • KonstantinosK Konstantinos

      Imagine we have QString file. File has directories any time. For example:

      C:/Qt/5.6/mingw49_32/bin/example.xml
      C:/Qt/raining/now/clouds/nature.png
      D:/sun/no_clouds/newworldorder/soon.txt

      Is there a smart way to take the names from this file:

      example.xml
      nature.png
      soon.txt

      or the last two names:

      bin/example.xml
      clouds/nature.png
      newworldorder/soon.txt

      There is the choice .remove.

      But you have to know what you want to remove, for example, file.remove("C:/Qt/5.6/mingw49_32/bin/").

      If you only want to remove all the folder - file names, except the last two ones?

      removefolder(2, file)?

      Thanks in advance.

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @Konstantinos
      Hi,
      Use the specialized API in QFile, QDir and QFileInfo. For example:

      const QString filePath("C:/Qt/5.6/mingw49_32/bin/example.xml");
      
      QFileInfo info(filePath);
      qDebug<< info.fileName() << endl << info.dir().path();
      

      Would output:

      example.xml
      C:/Qt/5.6/mingw49_32/bin
      

      Kind regards.

      Read and abide by the Qt Code of Conduct

      KonstantinosK 1 Reply Last reply
      3
      • kshegunovK kshegunov

        @Konstantinos
        Hi,
        Use the specialized API in QFile, QDir and QFileInfo. For example:

        const QString filePath("C:/Qt/5.6/mingw49_32/bin/example.xml");
        
        QFileInfo info(filePath);
        qDebug<< info.fileName() << endl << info.dir().path();
        

        Would output:

        example.xml
        C:/Qt/5.6/mingw49_32/bin
        

        Kind regards.

        KonstantinosK Offline
        KonstantinosK Offline
        Konstantinos
        wrote on last edited by
        #3

        @kshegunov

        Thank you for your help.

        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