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. QFile::rename() can not distinguish upper and lower case ?
Forum Updated to NodeBB v4.3 + New Features

QFile::rename() can not distinguish upper and lower case ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
18 Posts 7 Posters 1.6k Views 3 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.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by
    #1
    if (result_action == action_rename) {
            QDialog *dialog = new QDialog(this);
            dialog->setFixedSize(200, 100);
            dialog->setWindowTitle("重命名");
            QVBoxLayout *vbox = new QVBoxLayout;
            QLineEdit *lineEdit = new QLineEdit;
            lineEdit->setText(filename);
            vbox->addWidget(lineEdit);
            QHBoxLayout *hbox = new QHBoxLayout;
            QPushButton *pushButtonConfirm = new QPushButton("确定");
            QPushButton *pushButtonCancel = new QPushButton("取消");
            hbox->addWidget(pushButtonConfirm);
            hbox->addWidget(pushButtonCancel);
            vbox->addLayout(hbox);
            dialog->setLayout(vbox);
            connect(pushButtonConfirm, SIGNAL(clicked()), dialog, SLOT(accept()));
            connect(pushButtonCancel, SIGNAL(clicked()), dialog, SLOT(reject()));
            if (dialog->exec() == QDialog::Accepted) {
                QString newPath = QFileInfo(filepath).absolutePath() + "/" + lineEdit->text();
                qDebug() << "rename" << filepath << newPath;
                if (QFile::rename(filepath, newPath)) { //can not distinguish upper and lower case !
                    genList(QFileInfo(filepath).absolutePath());
                } else {
                    QMessageBox::critical(nullptr, "重命名错误", filepath + "\n无法重命名为\n" + newPath + "\n该文件已存在!", QMessageBox::Ok);
                }
            }
            dialog->close();
            return;
        }
    

    替代文字

    aha_1980A jsulmJ 2 Replies Last reply
    0
    • sonichyS sonichy
      if (result_action == action_rename) {
              QDialog *dialog = new QDialog(this);
              dialog->setFixedSize(200, 100);
              dialog->setWindowTitle("重命名");
              QVBoxLayout *vbox = new QVBoxLayout;
              QLineEdit *lineEdit = new QLineEdit;
              lineEdit->setText(filename);
              vbox->addWidget(lineEdit);
              QHBoxLayout *hbox = new QHBoxLayout;
              QPushButton *pushButtonConfirm = new QPushButton("确定");
              QPushButton *pushButtonCancel = new QPushButton("取消");
              hbox->addWidget(pushButtonConfirm);
              hbox->addWidget(pushButtonCancel);
              vbox->addLayout(hbox);
              dialog->setLayout(vbox);
              connect(pushButtonConfirm, SIGNAL(clicked()), dialog, SLOT(accept()));
              connect(pushButtonCancel, SIGNAL(clicked()), dialog, SLOT(reject()));
              if (dialog->exec() == QDialog::Accepted) {
                  QString newPath = QFileInfo(filepath).absolutePath() + "/" + lineEdit->text();
                  qDebug() << "rename" << filepath << newPath;
                  if (QFile::rename(filepath, newPath)) { //can not distinguish upper and lower case !
                      genList(QFileInfo(filepath).absolutePath());
                  } else {
                      QMessageBox::critical(nullptr, "重命名错误", filepath + "\n无法重命名为\n" + newPath + "\n该文件已存在!", QMessageBox::Ok);
                  }
              }
              dialog->close();
              return;
          }
      

      替代文字

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @sonichy yeah, some filesystems are case-insensitive. nothing Qt can do against.

      Regards

      Qt has to stay free or it will die.

      1 Reply Last reply
      2
      • sonichyS sonichy
        if (result_action == action_rename) {
                QDialog *dialog = new QDialog(this);
                dialog->setFixedSize(200, 100);
                dialog->setWindowTitle("重命名");
                QVBoxLayout *vbox = new QVBoxLayout;
                QLineEdit *lineEdit = new QLineEdit;
                lineEdit->setText(filename);
                vbox->addWidget(lineEdit);
                QHBoxLayout *hbox = new QHBoxLayout;
                QPushButton *pushButtonConfirm = new QPushButton("确定");
                QPushButton *pushButtonCancel = new QPushButton("取消");
                hbox->addWidget(pushButtonConfirm);
                hbox->addWidget(pushButtonCancel);
                vbox->addLayout(hbox);
                dialog->setLayout(vbox);
                connect(pushButtonConfirm, SIGNAL(clicked()), dialog, SLOT(accept()));
                connect(pushButtonCancel, SIGNAL(clicked()), dialog, SLOT(reject()));
                if (dialog->exec() == QDialog::Accepted) {
                    QString newPath = QFileInfo(filepath).absolutePath() + "/" + lineEdit->text();
                    qDebug() << "rename" << filepath << newPath;
                    if (QFile::rename(filepath, newPath)) { //can not distinguish upper and lower case !
                        genList(QFileInfo(filepath).absolutePath());
                    } else {
                        QMessageBox::critical(nullptr, "重命名错误", filepath + "\n无法重命名为\n" + newPath + "\n该文件已存在!", QMessageBox::Ok);
                    }
                }
                dialog->close();
                return;
            }
        

        替代文字

        jsulmJ Online
        jsulmJ Online
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @sonichy You forgot to tell us what filesystem is used on that device?
        As @aha_1980 pointed out not all file systems are case-sensitive (especially not those used on Windows).

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        sonichyS 2 Replies Last reply
        0
        • jsulmJ jsulm

          @sonichy You forgot to tell us what filesystem is used on that device?
          As @aha_1980 pointed out not all file systems are case-sensitive (especially not those used on Windows).

          sonichyS Offline
          sonichyS Offline
          sonichy
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • jsulmJ jsulm

            @sonichy You forgot to tell us what filesystem is used on that device?
            As @aha_1980 pointed out not all file systems are case-sensitive (especially not those used on Windows).

            sonichyS Offline
            sonichyS Offline
            sonichy
            wrote on last edited by
            #5

            @jsulm Linux

            jsulmJ JonBJ 2 Replies Last reply
            0
            • sonichyS sonichy

              @jsulm Linux

              jsulmJ Online
              jsulmJ Online
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @sonichy I did not ask about OS, but about the file system on that drive where you're trying to rename file.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              sonichyS 1 Reply Last reply
              3
              • sonichyS sonichy

                @jsulm Linux

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #7

                @sonichy
                On a case sensitive file system, like the ext... typically used in Linux, you can rename to change just case.

                On a case respecting, but insensitive, file system like NTFS/FAT typically used in Windows: I cannot test, but I it would not surprise me a rename of just case is ignored. In this case, you have to rename to something else first, then you can rename back with a different case from the original.

                I note that your example is on /media/..., perhaps a USB, you need to verify what file system that is formatted with. E.g. if you formatted it under Windows it is likely NTFS.

                Your examples only differ in Chinese/Japanese characters. I have no idea how those do or do not work. I would have thought that when you posted this question you would have taken the time before asking us to try with Latin characters only, and then report whether this is an Asian character set issue or not...? Whoops, I get it now, the characters are the error messages, not the end of the filenames! Sorry!

                jsulmJ 1 Reply Last reply
                3
                • JonBJ JonB

                  @sonichy
                  On a case sensitive file system, like the ext... typically used in Linux, you can rename to change just case.

                  On a case respecting, but insensitive, file system like NTFS/FAT typically used in Windows: I cannot test, but I it would not surprise me a rename of just case is ignored. In this case, you have to rename to something else first, then you can rename back with a different case from the original.

                  I note that your example is on /media/..., perhaps a USB, you need to verify what file system that is formatted with. E.g. if you formatted it under Windows it is likely NTFS.

                  Your examples only differ in Chinese/Japanese characters. I have no idea how those do or do not work. I would have thought that when you posted this question you would have taken the time before asking us to try with Latin characters only, and then report whether this is an Asian character set issue or not...? Whoops, I get it now, the characters are the error messages, not the end of the filenames! Sorry!

                  jsulmJ Online
                  jsulmJ Online
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @JonB said in QFile::rename() can not distinguish upper and lower case ?:

                  Your examples only differ in Chinese/Japanese characters

                  Take a closer look (hint: sound) :-)

                  @sonichy In a terminal execute

                  mount
                  

                  and search for /media/sonichy/Ventoy and tell us what file system is used there (or post that line here).

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  JonBJ 1 Reply Last reply
                  1
                  • jsulmJ jsulm

                    @JonB said in QFile::rename() can not distinguish upper and lower case ?:

                    Your examples only differ in Chinese/Japanese characters

                    Take a closer look (hint: sound) :-)

                    @sonichy In a terminal execute

                    mount
                    

                    and search for /media/sonichy/Ventoy and tell us what file system is used there (or post that line here).

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #9

                    @jsulm said in QFile::rename() can not distinguish upper and lower case ?:

                    Take a closer look (hint: sound) :-)

                    Ohhh. I looked at the message box, I thought the extra Chinese characters were the ends of the filenames, now I'm guessing they are the error messages!! I get it now, I have crossed out that comment in my earlier post!!

                    1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @sonichy I did not ask about OS, but about the file system on that drive where you're trying to rename file.

                      sonichyS Offline
                      sonichyS Offline
                      sonichy
                      wrote on last edited by
                      #10

                      @jsulm df -T -h
                      Linux system is ext4, file is in fuseblk (NTFS in Windows).

                      JKSHJ 1 Reply Last reply
                      0
                      • sonichyS sonichy

                        @jsulm df -T -h
                        Linux system is ext4, file is in fuseblk (NTFS in Windows).

                        JKSHJ Offline
                        JKSHJ Offline
                        JKSH
                        Moderators
                        wrote on last edited by JKSH
                        #11

                        @sonichy said in QFile::rename() can not distinguish upper and lower case ?:

                        file is in fuseblk (NTFS in Windows).

                        NTFS does not distinguish between uppercase and lowercase. So, WIN2003PE_Sound_Net.iso is the same name as WIN2003PE_sound_net.iso. EDIT: Actually, NTFS is case-sensitive. So I'm not sure what's happening here.

                        Linux system is ext4

                        Try to rename a file that is stored in the ext4 filesystem.

                        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                        jsulmJ kshegunovK 2 Replies Last reply
                        1
                        • JKSHJ JKSH

                          @sonichy said in QFile::rename() can not distinguish upper and lower case ?:

                          file is in fuseblk (NTFS in Windows).

                          NTFS does not distinguish between uppercase and lowercase. So, WIN2003PE_Sound_Net.iso is the same name as WIN2003PE_sound_net.iso. EDIT: Actually, NTFS is case-sensitive. So I'm not sure what's happening here.

                          Linux system is ext4

                          Try to rename a file that is stored in the ext4 filesystem.

                          jsulmJ Online
                          jsulmJ Online
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @JKSH @sonichy As far as I know NTFS CAN be case sensitive, but by default it isn't. So, that's the problem here. Do not depend on case sensitivity on Microsoft file systems.

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          2
                          • HoMaH Offline
                            HoMaH Offline
                            HoMa
                            wrote on last edited by HoMa
                            #13

                            To change only the case of character in a filename on ntfs you first have to rename it to a different name and only then you can give it the desired name by again renaming it.

                            JonBJ 1 Reply Last reply
                            1
                            • HoMaH HoMa

                              To change only the case of character in a filename on ntfs you first have to rename it to a different name and only then you can give it the desired name by again renaming it.

                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on last edited by JonB
                              #14

                              @HoMa said in QFile::rename() can not distinguish upper and lower case ?:

                              To change only the case of character in a filename on ntfs you first have to rename it to a different name and only then you can give it the desired name by again renaming it.

                              Which is why I wrote in my post above 2 days ago

                              On a case respecting, but insensitive, file system like NTFS/FAT typically used in Windows: I cannot test, but I it would not surprise me a rename of just case is ignored. In this case, you have to rename to something else first, then you can rename back with a different case from the original.

                              Not that anybody seems to actually bother to read solutions and try them, it seems....

                              HoMaH 1 Reply Last reply
                              0
                              • JonBJ JonB

                                @HoMa said in QFile::rename() can not distinguish upper and lower case ?:

                                To change only the case of character in a filename on ntfs you first have to rename it to a different name and only then you can give it the desired name by again renaming it.

                                Which is why I wrote in my post above 2 days ago

                                On a case respecting, but insensitive, file system like NTFS/FAT typically used in Windows: I cannot test, but I it would not surprise me a rename of just case is ignored. In this case, you have to rename to something else first, then you can rename back with a different case from the original.

                                Not that anybody seems to actually bother to read solutions and try them, it seems....

                                HoMaH Offline
                                HoMaH Offline
                                HoMa
                                wrote on last edited by
                                #15

                                @JonB no offense. You were perfectly right. Obviously I overlooked. And others, too.

                                1 Reply Last reply
                                2
                                • JKSHJ JKSH

                                  @sonichy said in QFile::rename() can not distinguish upper and lower case ?:

                                  file is in fuseblk (NTFS in Windows).

                                  NTFS does not distinguish between uppercase and lowercase. So, WIN2003PE_Sound_Net.iso is the same name as WIN2003PE_sound_net.iso. EDIT: Actually, NTFS is case-sensitive. So I'm not sure what's happening here.

                                  Linux system is ext4

                                  Try to rename a file that is stored in the ext4 filesystem.

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

                                  @JKSH said in QFile::rename() can not distinguish upper and lower case ?:

                                  So I'm not sure what's happening here.

                                  What @JonB wrote. NTFS is case sensitive, but it isn't case-aware. So it knows the difference, it just treats lower and uppercase the same.

                                  @JonB said in QFile::rename() can not distinguish upper and lower case ?:

                                  Not that anybody seems to actually bother to read solutions and try them, it seems....

                                  I do, but your english accent makes it hard to understand. ;P

                                  Read and abide by the Qt Code of Conduct

                                  JKSHJ 1 Reply Last reply
                                  2
                                  • kshegunovK kshegunov

                                    @JKSH said in QFile::rename() can not distinguish upper and lower case ?:

                                    So I'm not sure what's happening here.

                                    What @JonB wrote. NTFS is case sensitive, but it isn't case-aware. So it knows the difference, it just treats lower and uppercase the same.

                                    @JonB said in QFile::rename() can not distinguish upper and lower case ?:

                                    Not that anybody seems to actually bother to read solutions and try them, it seems....

                                    I do, but your english accent makes it hard to understand. ;P

                                    JKSHJ Offline
                                    JKSHJ Offline
                                    JKSH
                                    Moderators
                                    wrote on last edited by JKSH
                                    #17

                                    Sorry for skipping your post, @JonB! I tested it: QFile::rename("Hello.TXT", "hello.txt") works fine on my NTFS system (Windows 10, v2004, Qt 5.14.2 MinGW 32-bit). Renaming via the command prompt works fine too: > ren Hello.TXT hello.txt

                                    As @jsulm said, case-sensitivity is possible but disabled by default on NTFS. It can be enabled on a per-directory basis: https://devblogs.microsoft.com/commandline/per-directory-case-sensitivity-and-wsl/. However, I didn't need to enable it to rename "Hello.TXT" to "hello.txt".

                                    So NTFS does allow renames with case changes only. In @sonichy's case, maybe it's fuseblk that's blocking the operation? (I can't test this)

                                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                    1 Reply Last reply
                                    2
                                    • JonBJ Offline
                                      JonBJ Offline
                                      JonB
                                      wrote on last edited by JonB
                                      #18

                                      Sorry guys, I got irritated! :) Because someone was just saying what I had said a couple of days ago, and the OP had not sent whether that had resolved the issue. I apologise if my suggestion turns out to be incorrect. I thought I did recall that in our own Windows software (non-Qt) we had encountered this "case-only-rename" issue, and had found we needed to rename to something else and then back to desired case, but I appear to be mistaken.

                                      Nonetheless, if I were @sonichy I would at least try and see what the behaviour is if I renamed to something unrelated first and than back to the desired case. If that works we know for sure it;s a case issue; if that does not work then there is some other issue. That's what I would expect to do as a debugging effort in order to make an attempt to discover the problem.

                                      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