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. dir.mkdir not creating a directory

dir.mkdir not creating a directory

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 2.0k 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.
  • K Offline
    K Offline
    Krag
    wrote on last edited by
    #1
    void MainWindow::on_pushButton_clicked()
    {
        if(currentDir.isEmpty()) return;
            qDebug() << currentDir; //"C:/Program Files"
        QDir dir(currentDir);
    
        if(!dir.exists()) return;
        bool ok;
        QString name = QInputDialog::getText(this, "Folder name", "Enter a folder name", QLineEdit::Normal, QDir::home().dirName(), &ok);
        if(ok && !name.isEmpty())
            if(dir.mkdir(name))
                qDebug() << "Folder created: " << name;
            else
                qDebug() << "Folder not created";
    }
    

    It outputs that the folder was successfully created but I don't see one when I go to C:/Program Files
    What could be the problem?

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

      It works for me i.e. it prints "folder not created".
      Writing to "Program Files" requires administrative privileges. Are you running your program as admin?

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Krag
        wrote on last edited by
        #3

        Ah, it does create folders in other directories. Although it is weird that it always outputs that the folder was created even if it wasn't.
        Thanks.

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

          Sounds weird indeed. What OS and Qt version are you running?

          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