Open Bug 317646 Opened 19 years ago Updated 2 years ago

nsIFile.moveTo() has problem renaming a file to the same name but with different case (on Windows)

Categories

(Core :: XPCOM, defect, P3)

x86
Windows XP
defect

Tracking

()

People

(Reporter: mimecuvalo, Unassigned)

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5

moveTo() will throw an exception if you are just doing a case change on a file on Windows.
Example:
test.xul -> TEST.XUL

Same name but different case and it throws this:
[Exception... "Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsILocalFile.moveTo]" nsresult: "0x80520012 (NS_ERROR_FILE_NOT_FOUND)"

Reproducible: Always

Steps to Reproduce:
1.  On Windows, rename a file using moveTo() from lowercase to uppercase or vice versa.



Expected Results:  
Should work or there should be a cleaner way to rename a file.
Summary: nsiFile.moveTo() has problem renaming a file to the same name but with different case (on Windows) → nsIFile.moveTo() has problem renaming a file to the same name but with different case (on Windows)
The windows file system is case-preserving, but not case-sensitive. You therefore cannot simply change the case of a file's name.
Status: UNCONFIRMED → RESOLVED
Closed: 18 years ago
Resolution: --- → INVALID
I think you misunderstand, perhaps.  It will work as expected and it will make the change for you but it unnecessarily throws an exception along with it.  You can try it out on my program FireFTP ( http://fireftp.mozdev.org ).  It's just an inconvenience to the programmer that I have to check for it and realize that it is an invalid exception, that's all.  Here's how I'm dealing with it in my code:

try {
  var newFile = this.init(file.parent.path + gSlash + newName);

  if (newFile && newFile.exists() && (gSlash == '/' || oldName.toLowerCase() != newName.toLowerCase())) {
    error(gStrbundle.getString("renameFail"));
    return false;
  }

  file.moveTo(null, newName);           // rename the file
} catch (ex) {
  if (gSlash == '\\' && oldName.toLowerCase() == newName.toLowerCase()) {
                 // we renamed the file the same but with different case
    return true; // for some reason this throws an exception
  }

  debug(ex);
  error(gStrbundle.getString("renameFail"));
  return false;
}
(In reply to comment #2)
> I think you misunderstand, perhaps.  It will work as expected and it will make
> the change for you but it unnecessarily throws an exception along with it.

OK, reopening for investigation.
Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---
mass reassigning to nobody.
Assignee: dougt → nobody
Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3
Assignee: nobody → netzen
Assignee: netzen → nobody
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.