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. .exists method returns false for the files stored in C: [Windows]
QtWS25 Last Chance

.exists method returns false for the files stored in C: [Windows]

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

    Hi all, my problem is when I try to check the existence of a file stored in the C: (ex: C:\\myFile.bin), .exist method return false while the file is already exist.

    What did I notice is that the method returns false when :

    • The file name is composed with one letter, like : a.bin, k.bin, f.bin,..
    • The file name is : Ntest.

    When I change the file name to another name other than the previous examples, the method returns true , and this seems so weird.

    PS:

    • The files which cannot be detected, become detectable outside the C: or when they are located inside a C: folder (ex: C:\\folderName\fileName.bin).
    • I am working with bin files.
    • I don't have the admin rights in the env where my code is running.

    The code :

    QString qFilePath = QString::fromWCharArray(filePath);
    
        if(!QFileInfo(qFilePath).exists()){
            return ERROR_NO_FILE;
        }
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      This example works fine for me with Qt 6.5 on windows 10:

      #include <QtCore>
      int main(int argc, char** argv)
      {
          QCoreApplication app(argc, argv);
          if (QFile("C:\\t.bin").exists()) {
              qDebug() << "exists";
          }
          else {
              qDebug() << "Does not exist";
          }
          return 0;
      }
      

      What Qt version and OS do you use. Please also check it with my simple example instead in your code.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      D 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        This example works fine for me with Qt 6.5 on windows 10:

        #include <QtCore>
        int main(int argc, char** argv)
        {
            QCoreApplication app(argc, argv);
            if (QFile("C:\\t.bin").exists()) {
                qDebug() << "exists";
            }
            else {
                qDebug() << "Does not exist";
            }
            return 0;
        }
        

        What Qt version and OS do you use. Please also check it with my simple example instead in your code.

        D Offline
        D Offline
        djalla
        wrote on last edited by djalla
        #3

        Thanks @Christian-Ehrlicher for your time, your code works fine, and mine as well; the problem was with the file path sent to the API (frontend side).

        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