QFile::rename() can not distinguish upper and lower case ?
-
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; }
-
@sonichy
On a case sensitive file system, like theext...
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! -
@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).
-
@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!!
-
@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,EDIT: Actually, NTFS is case-sensitive. So I'm not sure what's happening here.WIN2003PE_Sound_Net.iso
is the same name asWIN2003PE_sound_net.iso
.Linux system is ext4
Try to rename a file that is stored in the ext4 filesystem.
-
@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....
-
@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
-
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)
-
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.