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. Putting / checking numbers in file names
QtWS25 Last Chance

Putting / checking numbers in file names

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 1.5k Views
  • 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.
  • P Offline
    P Offline
    phil63
    wrote on last edited by
    #1

    Hi,
    I am using QT4 with QtCreator and windowsXP.

    I would like to save text-files in giving them names made with letters and a number at the end (for example cours12).

    1. Checking the last number used for the files (cours1/cours2/cours3/cours4 already exist)
      2)5 is not used yet. Thus cours5 has to be created and saved

    Could you help me to do this. Thank you in advance

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SergioDanielG
      wrote on last edited by
      #2

      Hi phil63, you can use something like this

      @int n = 0;
      while (true){
      QString f = qApp->tr("cours%1.txt").arg(n);
      if (! QFile::exists ( f ))
      break;
      else
      n += 1;
      }
      //here you can continue and create coursN file
      @

      Hope it's util.
      Regards

      www.ftatv.com.ar El foro argentino de la TV libre

      1 Reply Last reply
      0
      • P Offline
        P Offline
        phil63
        wrote on last edited by
        #3

        thank you for your help.
        f is the file or the name of the file?

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          the static method "exists":http://qt-project.org/doc/qt-4.8/qfile.html#exists takes a string. So, it must be the name of the file.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SergioDanielG
            wrote on last edited by
            #5

            Sorry for the omission. Exactly, f is file name.
            Regards.

            www.ftatv.com.ar El foro argentino de la TV libre

            1 Reply Last reply
            0
            • P Offline
              P Offline
              phil63
              wrote on last edited by
              #6

              Thank you to both of you.

              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